Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建javascript执行器以使元素在SeleniumWebDriver中可见_Javascript_Jquery_Html_Selenium_Selenium Webdriver - Fatal编程技术网

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

如何创建javascript执行器以使元素在SeleniumWebDriver中可见,javascript,jquery,html,selenium,selenium-webdriver,Javascript,Jquery,Html,Selenium,Selenium Webdriver,目前我正在开发SeleniumWebDriver。我有很多下拉列表,如可视化、周期、类型等,。下拉列表中有许多选项。我想从下拉列表中选择一个选项,我的目标是通过ID查找元素 但是在HTML标记中,元素不可见,无法选择选项。我验证了这么多的问题,他们提到了使用javascript exceutor 有人能帮我看一下html标签的java脚本吗: <select id="periodId" name="period" style="display: none;"> <option

目前我正在开发SeleniumWebDriver。我有很多下拉列表,如可视化、周期、类型等,。下拉列表中有许多选项。我想从下拉列表中选择一个选项,我的目标是通过ID查找元素

但是在HTML标记中,元素不可见,无法选择选项。我验证了这么多的问题,他们提到了使用javascript exceutor

有人能帮我看一下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>

过去4周
过去52周
日期范围
周范围
月份范围
年初至今

您可以尝试使用以下脚本使元素可见:
document.getElementById('periodId').style.display='block'

在java代码中,可以使用以下代码执行此脚本:

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('periodId').style.display='block';");
如果您只想在下拉列表中选择一个选项,可以使用以下java代码:

Select select = new Select(driver.findElement(By.id("periodId")));
select.deselectAll();
select.selectByVisibleText("Last 4 Weeks");

您可以尝试使用以下脚本使元素可见:
document.getElementById('periodId').style.display='block'

在java代码中,可以使用以下代码执行此脚本:

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('periodId').style.display='block';");
如果您只想在下拉列表中选择一个选项,可以使用以下java代码:

Select select = new Select(driver.findElement(By.id("periodId")));
select.deselectAll();
select.selectByVisibleText("Last 4 Weeks");

是否有任何解决方案请向我建议一些在代码中实现的想法。是否有任何解决方案请向我建议一些在代码中实现的想法。您使用的语言是什么?我使用java并在selenium WebDriverTanks中运行脚本,以获得您的回复。我已经尝试过这些代码了。问题是元素不可见,它显示错误为。ElementNotVisibleException:元素当前不可见,因此可能无法与命令持续时间或超时进行交互:16毫秒。我需要解决方案是否有其他方法使元素可见,然后我需要选择该选项。我使用了上述代码,我得到了错误,因为您可能只能取消选择multi-Selector的所有选项。如果确实正确,您可以将问题标记为正确。或者单击问题附近的“向上”行(如果有帮助)。这是对帮助表示感谢的方式!您使用的语言是什么?我使用java并在selenium WebDriverTanks中运行脚本,以获得您的回复。我已经尝试过这些代码了。问题是元素不可见,它显示错误为。ElementNotVisibleException:元素当前不可见,因此可能无法与命令持续时间或超时进行交互:16毫秒。我需要解决方案是否有其他方法使元素可见,然后我需要选择该选项。我使用了上述代码,我得到了错误,因为您可能只能取消选择multi-Selector的所有选项。如果确实正确,您可以将问题标记为正确。或者单击问题附近的“向上”行(如果有帮助)。这是对帮助表示感谢的方式!