您好,我正在尝试选择加拿大的selenium webdriver(on jav)和mozilla
我的代码是:
Select select = new Select(driver.findElement(By.id("address.country")));
select.selectByValue("CA");它不工作了,有人能帮帮我吗?
<select id="address.country" name="countryIso" class="dd dd"><option value="" disabled="disabled" selected="selected">Please select a country</option>
<option value="CA">Canada</option><option value="US">United States</option></select></div>
发布于 2015-01-05 14:08:13
有关如何通过不同方式选择值的详细说明,请观看以下视频:How to select a value from listbox in different ways
我尝试了下面的代码,它们都工作得很好。
这是你的html:
<!DOCTYPE html>
<html>
<body>
<select id="address.country" name="countryIso" class="dd dd">
<option value="" disabled="disabled" selected="selected">Please select a country</option>
<option value="CA">Canada</option>
<option value="US">United States</option></select></div>
</body>
</html>以下是Selenium代码:
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/Programming%20Samples/Temp.html");
WebElement ele=driver.findElement(By.id("address.country"));
Select sel=new Select(ele);
// sel.selectByVisibleText("Canada");
sel.selectByValue("CA");如果您仍然看到一些问题,请获取最新版本的Selenium和Firefox。
发布于 2015-01-05 13:15:54
请尝试使用以下代码
WebElement country = driver.findElement(By.id("address.country"));
new Actions(driver).moveToElement(country).perform();
new Select(country)
.selectByVisibleText("Canada");或
Select countryValue = new Select(
country);
countryValue.selectByValue("CA");https://stackoverflow.com/questions/27770998
复制相似问题