元素找不到带有文本的selenium Web驱动程序
Element cannot locate with the text- selenium webdriver
目前正在使用Java语言开发selenium网络驱动程序和。
Log.info("Clicking on To weekrange dropdown");
JavascriptExecutor executor25 = (JavascriptExecutor)driver;
executor25.executeScript("document.getElementById('toWeekYear).style.display='block';");
Select select25 = new Select(driver.findElement(By.id("toWeekYear")));
select25.selectByVisibleText("2011");
JavascriptExecutor executor26 = (JavascriptExecutor)driver;
executor26.executeScript("document.getElementById('toWeekYear).style.display='block';");
Select select26 = new Select(driver.findElement(By.id(" toWeek")));
select26.selectByVisibleText(" W 5");
Thread.sleep(6000);
在上面的代码中,我试图选择周范围,它的形式是选择2011年和第五周。这些值是从下拉列表中选择的。问题是在选择第一个下拉列表时,它选择的是年份,而在尝试选择第二个下拉列表的时候,我得到了错误。找不到带文本的元素:W 1
这是HTML标签:
<select id="fromWeekYear" style="width:60px" name="fromWeekYear">
<option value="2010"> 2010</option>
<option value="2011"> 2011</option>
<option value="2012"> 2012</option>
<option selected="" value="2013"> 2013</option>
</select>
<select id="fromWeek" style="width:60px" name="fromWeek">
<option value="1"> W 1</option>
<option value="2"> W 2</option>
<option value="3"> W 3</option>
<option value="4"> W 4</option>
<option value="5"> W 5</option>
和
<select id="toWeekYear" style="width:60px" name="toWeekYear">
<option value="2010"> 2010</option>
<option value="2011"> 2011</option>
<option value="2012"> 2012</option>
<option selected="" value="2013"> 2013</option>
</select>
<select id="toWeek" style="width:60px" name="toWeek">
<option value="1"> W 1</option>
<option value="2"> W 2</option>
<option value="3"> W 3</option>
<option value="4"> W 4</option>
<option value="5"> W 5</option>
这是我的fromweek javascript:
Log.info("Clicking on From weekrange dropdown");
JavascriptExecutor executor23 = (JavascriptExecutor)driver;
executor23.executeScript("document.getElementById('fromWeekYear').style.display='block';");
Select select23 = new Select(driver.findElement(By.id("fromWeekYear")));
select23.selectByVisibleText("2011");
JavascriptExecutor executor24 = (JavascriptExecutor)driver;
Thread.sleep(6000);
executor24.executeScript("document.getElementById('fromWeek').style.display='block';");
Select select24 = new Select(driver.findElement(By.id("fromWeek")));
select24.selectByVisibleText(" W 1");
Thread.sleep(6000);
试试这个:
new Select(driver.findElement(By.id("fromWeekYear")).selectByValue("2010");
new Select(driver.findElement(By.id("toWeek")).selectByValue("1");
值是单一的,使用值。
如果通过文本,您的文本有空间:
new Select(driver.findElement(By.id("fromWeekYear")).selectByVisibleText(" 2010");
new Select(driver.findElement(By.id("toWeek")).selectByVisibleText(" W 1");
另一个问题是,您的空间可能是(amp;nbsp;)
您有一些间距问题:
driver.findElement(By.id(" toWeek")));
id中不应该有空格:
driver.findElement(By.id("toWeek")));
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- WebDriverException:tinyMCE未在selenium Web driver java中定义
- Selenium Web驱动程序和javascript
- Xpath对Selenium Web驱动程序无效”;Xpath未找到”;
- Sencha禁用按钮和Selenium Web驱动程序
- 如何使用Selenium Web驱动程序验证电子邮件
- 在Selenium Web驱动程序2.0中找不到元素
- 使用Java脚本跟踪网页中是否有Ajax请求,或者通过Selenium Web驱动程序拦截XMLHttpRequest
- 元素找不到带有文本的selenium Web驱动程序
- 无法使用Javascript和Selenium Web驱动程序保存保存在表单元格中的文本
- Selenium Web驱动程序访问Jquery中的Javascript全局变量
- Selenium Web驱动程序使用Java查找Element
- C#Selenium Web驱动程序在Internet explorer中捕获javascript错误
- 获取 selenium Web 驱动程序 java 中元素的类名
- 使用Selenium Web驱动程序注入自定义JS代码
- 用于解析的Selenium Web驱动程序(Ruby)
- Selenium Web驱动程序的执行由于javascript等待条件而陷入停滞
- 如何使用selenium web驱动程序单击导航栏
- Selenium Web驱动程序定位器
- Selenium Web驱动程序:execute_script can't执行自定义方法和外部javascrip