简体   繁体   English

如何创建javascript执行器以使元素在selenium webdriver中可见

[英]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.

相关问题 如何使元素在Selenium WebDriver中可见? - How to make element visible in selenium webdriver? JavaScript-Selenium Webdriver。 如何检查元素是否可见 - JavaScript - Selenium Webdriver. How to check if element is visible Selenium Webdriver:元素当前不可见 - Selenium Webdriver: Element is not currently visible 如何使用Java脚本执行程序使隐藏元素可见 - How to make the hidden element visible using java script executor 如何使用 JavaScript 单击 Selenium WebDriver 中的元素? - How to click an element in Selenium WebDriver using JavaScript? Selenium-webdriver JS - 如何等待元素可见 - Selenium-webdriver JS - how to wait until an element is visible 通过在Selenium Webdriver的Javascript执行程序中使用Javascript XPATH获取iframe内容 - Get iframe content by using Javascript XPATH in Javascript executor for selenium webdriver 无法通过 Selenium Webdriver 甚至 Javascript 执行程序滚动网页 - Cannot Scroll Webpage by Selenium Webdriver or even Javascript Executor 如何使用Selenium webdriver .NET通过JavaScript更改元素的值 - How to change value of element via JavaScript with Selenium webdriver .NET Selenium-WebDriver 如何使用 javascript 和 firefox 浏览器突出显示元素 - Selenium-WebDriver how to highlight element using javascript and firefox browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM