Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.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
无法使用Java/webDriver中的select类更改选择框值_Java_Javascript_Xpath_Selenium_Webdriver - Fatal编程技术网

无法使用Java/webDriver中的select类更改选择框值

无法使用Java/webDriver中的select类更改选择框值,java,javascript,xpath,selenium,webdriver,Java,Javascript,Xpath,Selenium,Webdriver,您是否尝试过使用SelectByValue而不是SelectByVisibleText?您提到select标记不可见,这就是为什么驱动程序会给您一个错误,即由于它不可见,您无法与其交互 Selenium过去允许与隐藏元素交互,但不允许与webdriver交互,因为它希望更恰当地模拟用户交互 要在webdriver中实现这一点,您需要首先通过执行使其在页面上可见的操作,然后使用selectbylabel使select标记可见。您的xpath似乎也在考虑span id,而select标记本身有一个标

您是否尝试过使用
SelectByValue
而不是
SelectByVisibleText

您提到select标记不可见,这就是为什么驱动程序会给您一个错误,即由于它不可见,您无法与其交互

Selenium过去允许与隐藏元素交互,但不允许与webdriver交互,因为它希望更恰当地模拟用户交互

要在webdriver中实现这一点,您需要首先通过执行使其在页面上可见的操作,然后使用selectbylabel使select标记可见。您的xpath似乎也在考虑span id,而select标记本身有一个标识它的id。我建议直接使用select的id,而不是采用相对的方式。

使用以下方法:

Select select = driver.findElement(By.xpath("//span[@id='outDuration']/span/select")).SelectByVisibleText("5");

Exception: Element is not currently visible and so may not be interacted with

如果出现可见性异常,则必须使用
JavaScript Executor

那么,这是什么,java还是JavaScript?这并不能回答这个问题。若要评论或要求作者澄清,请在其帖子下方留下评论-您可以随时在自己的帖子上发表评论,一旦您有足够的评论,您就可以发表评论。这是本页面的问题之一,它不允许新来者通过评论请求其他信息,因此他们可以给出正确的答案,因为我没有足够的代表,所以我只有两个选择,等待其他人请求信息,而不是我的代表,或者这样做,给出一个不是真正的答案的答案增加你的声誉:)@RiccoE
<span class="selectBox-label">5</span> 
Select select = driver.findElement(By.xpath("//span[@id='outDuration']/span/select")).SelectByVisibleText("5");

Exception: Element is not currently visible and so may not be interacted with
Select select=new Select(Utils.driver.findElement(By.xpath("//span[@id='outDuration']//select[@id='duration']")));
select.deselectAll();
select.selectByVisibleText("5");