I am trying to simply click on the dropdown list that is displayed after I enter the word advance. But I keep getting an error being thrown. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
public void supplier (WebDriver driver)
{
Actions action = new Actions(driver);
WebElement supplierLink = driver.findElement(By.id("_searchstring"));
supplierLink.sendKeys("Advance");
//*[@id="/app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108"]
//WebDriverWait wait = new WebDriverWait(driver, 5);
//wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108")));
WebElement clickadvance = driver.findElement(By.id("/app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108"));
action.moveToElement(clickadvance).perform();
}
CodePudding user response:
Please add wait conditions in your code, this will work,
WebDriverWait wait = new WebDriverWait(driver, 20);
By optionXpath = By.id("/app/accounting/transactions/transactionlist.nl?Transaction_TYPE=Custom108");
wait.until(ExpectedConditions.elementToBeClickable(optionXpath));
driver.findElement(optionXpath).click();
if not your xpath is wrong, change the xpath accordingly.
CodePudding user response:
Please use this xpath
//span[text()='Advance']/parent::a[@role='option' and contains(@id,'/app/accounting/transactions/transactionlist.nl?')]
Please make sure it should represent the correct element.
Code trial 1 :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Advance']/parent::a[@role='option' and contains(@id,'/app/accounting/transactions/transactionlist.nl?')]"))).click();