WebDriver - Selenium我无法选择下拉选项

时间:2017-11-13 10:47:40

标签: java selenium selenium-webdriver webdriver

我无法理解问题是什么,尝试了不同的选择方式,我在下面举例说明...... 1.您必须选择或单击选择。 2.选择或单击所需的语言。 但WebDriver没有看到,没有找到这些元素,但在DOM中它们是。 您需要转到LinkedIn个人资料,设置,语言选择。

//Before select dropdown.
WebElement language = driver.findElement(By.id("setting-select-language"));
language.click();
//Select dropdown.
Select make = new Select(driver.findElement(By.name("selectLanguage")));
make.selectByValue("en_US");
//Or 
Actions act = new Actions(driver);  
//XPath of dropdown.       
act.moveToElement(driver.findElement(By.name("selectLanguage"))).click().perform();
//XPath of option in the dropdown.
act.moveToElement(driver.findElement(By.xpath("//*[@id='setting-select-language-content']/form/div/select/option[16]"))).click().perform();

2 个答案:

答案 0 :(得分:0)

focus = true focus = false

当您点击选择它时,会更改focus = true

答案 1 :(得分:0)

我相信你选择的定位器不正确,尝试类似下面的代码:

WebElement language = driver.findElement(By.id("setting-select-language"));
language.click();
Select make = new Select(driver.findElement(By.name("//*[@id='setting-select-language-content']/form/div/select")));
make.selectByValue("en_US");