1
我无法点击列表中的某个元素,一旦我点击了下拉列表?Webdriver等待TEXT出现
我创建的方法不起作用。
public static void waitForTextToAppearAndClick(WebDriver driver, WebElement element, String textToAppear) throws InterruptedException{
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(element));
WebElement locator = element;
locator.click();
WebElement textToClick = driver.findElement(By.linkText(textToAppear));
wait.until(ExpectedConditions.elementToBeClickable(textToClick));
textToClick.click();
}
使用thread.sleep
似乎工作,但我不想使用此方法,任何人都可以推荐一个方法来等待和特定的文本元素上单击一次我点击了主键?
public static void waitForTextToAppearAndClick(WebDriver driver, WebElement element, String textToAppear) throws InterruptedException{
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(element));
WebElement locator = element;
locator.click();
Thread.sleep(3000);
driver.findElement(By.linkText(textToAppear)).click();;
}
请注意我需要点击BBQ酱,需要点击烧烤酱当thread.sleep()
成功
感谢您的帮助
可以还添加了异常跟踪供我们参考? –
使用现有的ExpectedConditions,如 - \t textToBePresentInElement或\t textToBePresentInElementValue。检查API - \t textToBePresentInElement。 – Grasshopper
请发布相关的HTML。 – JeffC