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