[英]how to handle the selenium script to validate the completion of report which takes 20 minutes using selenium webdriver?
[英]How to handle AutoSearch completion using Selenium webdriver
我正在使用JAVA運行Selenium Web驅動程序,並且面臨自動建議輸入文本字段的問題。 當我在文本字段中輸入字符串“ books”時,將顯示一個選項。 然后,我想單擊或選擇自動建議菜單上填充的輸入。
下面是代碼:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.amazon.com/");
driver.findElement(By.id("twotabsearchtextbox")).sendKeys("books");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("gwcswTooltip")));
List<WebElement> findElements = driver.findElements((By.id("gwcswTooltip").name("books on")));
for (WebElement webElement : findElements)
{
System.out.println(webElement.getText());
}
您只需要選擇合適的定位器即可。
添加以下行
List<WebElement> findElements = driver.findElements((By.xpath("//div[@id='srch_sggst']/div")));
代替
List<WebElement> findElements = driver.findElements((By.id("gwcswTooltip").name("books on")));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.