Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 尝试从Selenium web automation中的下拉列表中选择一个选项-错误-“;ElementNotInteractiableException:无法滚动到视图中;_Java_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

Java 尝试从Selenium web automation中的下拉列表中选择一个选项-错误-“;ElementNotInteractiableException:无法滚动到视图中;

Java 尝试从Selenium web automation中的下拉列表中选择一个选项-错误-“;ElementNotInteractiableException:无法滚动到视图中;,java,selenium,xpath,css-selectors,webdriverwait,Java,Selenium,Xpath,Css Selectors,Webdriverwait,代码说明: 我正在尝试使网页自动化。主页本身有一个名为“所有”的下拉列表。如果单击“全部”下拉菜单,将有不同的选项可供选择。使用Selenium automation,我尝试单击下拉列表并选择其中一个选项 package com.web.automation; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; imp

代码说明:

我正在尝试使网页自动化。主页本身有一个名为“所有”的下拉列表。如果单击“全部”下拉菜单,将有不同的选项可供选择。使用Selenium automation,我尝试单击下拉列表并选择其中一个选项

package com.web.automation;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class dropDown {
WebDriver driver;
    @BeforeMethod
    public void site() throws InterruptedException{
        System.setProperty("webdriver.gecko.driver", "geckodriver");
        driver =  new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("https://www.amazon.com/");
        }
    
        @AfterMethod
        public void close(){
            driver.close();
            }
        @Test
        public void register() throws InterruptedException{
        Select s = new Select(driver.findElement(By.xpath("//select[@id='searchDropdownBox']")));
        s.selectByValue("search-alias=alexa-skills");
        }
}
错误:

Select s = new Select(driver.findElement(By.xpath("//select[@id='searchDropdownBox']")));
s.selectByValue("search-alias=alexa-skills");
失败:寄存器
org.openqa.selenium.elementNotInteractiableException:元素无法滚动到视图中
构建信息:版本:“3.141.59”,修订版:“e82be7d358”,时间:“2018-11-14T08:17:03”

要从下拉列表中选择文本为
书籍的选项,您需要为
元素归纳可折叠()
,您可以使用以下任一选项:

  • 使用CSS选择器和
    selectByVisibleText()

  • 使用xpath和
    selectByValue()


要从下拉列表中选择文本为
Books
的选项,您需要将
元素归纳为可折叠()
,您可以使用以下任一选项:

  • 使用CSS选择器和
    selectByVisibleText()

  • 使用xpath和
    selectByValue()


所有部门;原文上面的文字就是元素。由于文本限制,我无法添加整个html元素尝试使用ExpectedConditions.presenceOfElement添加显式等待。各部门;原文上面的文字就是元素。由于文本限制,我无法添加整个html元素。请尝试使用ExpectedConditions.presenceOfElement添加显式等待。太好了!这对我将来会有帮助。但我想我已经找到了搜索框的元素,而不是下拉按钮。因为下拉列表是div元素。由于我正在学习一个教程,我相信很快我就会找到为div标签选择下拉选项的解决方案,因为我提到的上述代码将用于“select”标签。感谢您的回复@DebanjanB.@KrishnaveniRaju您不是在尝试按照代码试用版
driver.findElement(By.xpath(//select[@id='searchDropdownBox'])中的xpath与相同的
标记交互吗
?太好了!这对我将来会有帮助。但我想我已经找到了搜索框的元素,而不是下拉按钮。因为下拉列表是div元素。由于我正在学习一个教程,我相信很快我就会找到为div标签选择下拉选项的解决方案,因为我提到的上述代码将用于“select”标签。感谢您的回复@DebanjanB@KrishnaveniRaju您不是在尝试按照代码试用版
driver.findelelement(By.xpath(//select[@id='searchDropdownBox'])中的xpath与相同的
标记交互吗?
FAILED: register
org.openqa.selenium.ElementNotInteractableException: Element <option> could not be scrolled into view
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("select#searchDropdownBox")))).selectByVisibleText("Books");
new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//select[@id='searchDropdownBox']")))).selectByValue("search-alias=stripbooks-intl-ship");