[英]How to create javascript executor to make element visible in selenium webdriver
Currently am working on selenium webdriver. 目前正在研究selenium webdriver。 I have many drop downs like visualization, Period, Type etc,. 我有很多可视化,周期,类型等下拉菜单。 In the drop down many options are there. 在下拉列表中有很多选项。 I want to select an option from the drop down and my target is to find element is through ID. 我想从下拉列表中选择一个选项,我的目标是通过ID查找元素。
But in the HTML tag the element is not visible to select the option. 但是在HTML标记中,元素不可见以选择该选项。 I verified so many question in that they are mentioning use javascript exceutor. 我验证了很多问题,因为他们提到使用javascript exceutor。
Can any one please help me the java script for the html tag: 任何人都可以帮我html标签的java脚本:
<select id="periodId" name="period" style="display: none;">
<option value="l4w">Last 4 Weeks</option>
<option value="l52w">Last 52 Weeks</option>
<option value="daterange">Date Range</option>
<option value="weekrange">Week Range</option>
<option selected="" value="monthrange">Month Range</option>
<option value="yeartodate">Year To Date</option>
</select>
You can try to use the following script to make element visible: document.getElementById('periodId').style.display='block';
您可以尝试使用以下脚本使元素可见: document.getElementById('periodId').style.display='block';
In java code this script can be executed with the following code: 在java代码中,可以使用以下代码执行此脚本:
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('periodId').style.display='block';");
If you just want to select an option in drop down you can use the following java code: 如果您只想在下拉列表中选择一个选项,则可以使用以下java代码:
Select select = new Select(driver.findElement(By.id("periodId")));
select.deselectAll();
select.selectByVisibleText("Last 4 Weeks");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.