为 NetSuite 自动显示列表后无法单击下拉列表选项

Unable to click on dropdown list option after list is displayed automatically for NetSuite

我试图简单地单击输入单词 advance 后显示的下拉列表。但是我不断收到错误消息。线程“main”中的异常org.openqa.selenium.NoSuchElementException:没有这样的元素:无法定位元素:

 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();
        
    }

请在您的代码中添加等待条件,这会起作用,

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();

如果不是您的 xpath 错误,请相应地更改 xpath。

请使用这个 xpath

//span[text()='Advance']/parent::a[@role='option' and contains(@id,'/app/accounting/transactions/transactionlist.nl?')]

请确保它代表正确的元素。

代码试用 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();