Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Select 如何在webdriver中处理自动完成列表?_Select_Webdriver_Selenium Webdriver - Fatal编程技术网

Select 如何在webdriver中处理自动完成列表?

Select 如何在webdriver中处理自动完成列表?,select,webdriver,selenium-webdriver,Select,Webdriver,Selenium Webdriver,如何从自动完成下拉列表中选择国家/地区名称 请提供谷歌搜索代码的建议,以便我能理解。如果您的下拉列表是可编辑的,您可以使用发送键直接键入值,否则您需要根据需要模拟向下箭头键操作。但一次也不明智,因为如果在下拉列表中添加新值,无论如何在这种情况下,会有固定值,因为国家的数量是一个常数,那么它会变得混乱 driver.findElement(locator).sendKeys(countryName , Keys.TAB); 或 请尝试以下代码: WebElement dropdown = dri

如何从自动完成下拉列表中选择国家/地区名称


请提供谷歌搜索代码的建议,以便我能理解。

如果您的下拉列表是可编辑的,您可以使用发送键直接键入值,否则您需要根据需要模拟向下箭头键操作。但一次也不明智,因为如果在下拉列表中添加新值,无论如何在这种情况下,会有固定值,因为国家的数量是一个常数,那么它会变得混乱

driver.findElement(locator).sendKeys(countryName , Keys.TAB);


请尝试以下代码:

WebElement dropdown = driver.findElement(By.....);
Select dropdownSelect = new Select(dropdown);
dropdownSelect.selectByVisibleText(itemStr) or selectByValue(value);

这可以很好地工作driver.findElementlocator.sendKeysKeys.DOWN;
WebElement dropdown = driver.findElement(By.....);
Select dropdownSelect = new Select(dropdown);
dropdownSelect.selectByVisibleText(itemStr) or selectByValue(value);
Link : http://www.mythoughts.co.in/2012/05/getting-google-search-auto-suggestions.html#.Ul-lJdi1Zbc
@Test  
  public void SearchSuggestion() {  

  driver.get("http://google.com");  
  driver.findElement(By.id("gbqfq")).sendKeys("vam");  
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  

   WebElement table = driver.findElement(By.className("gssb_m"));   
   List<webelement> rows = table.findElements(By.tagName("tr"));   
   Iterator<webelement> i = rows.iterator();   
   System.out.println("-----------------------------------------");   
   while(i.hasNext()) {   
           WebElement row = i.next();   
           List<webelement> columns = row.findElements(By.tagName("td"));   
           Iterator<webelement> j = columns.iterator();   
           while(j.hasNext()) {   
                   WebElement column = j.next();   
                   System.out.println(column.getText());   
           }   
           System.out.println("");   

   System.out.println("-----------------------------------------");   
   }   
  }   
}
driver.findElement(By.id("your searchBox")).sendKeys("your partial keyword");
Thread.sleep(3000);
List <WebElement> listItems = driver.findElements(By.xpath("your list item locator"));
listItems.get(0).click();
driver.findElement(By.id("your searchButton")).click()