Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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 无法单击选项卡的子值,获取';元素不可见';硒异常_Java_Selenium_Selenium Webdriver_Webdriver - Fatal编程技术网

Java 无法单击选项卡的子值,获取';元素不可见';硒异常

Java 无法单击选项卡的子值,获取';元素不可见';硒异常,java,selenium,selenium-webdriver,webdriver,Java,Selenium,Selenium Webdriver,Webdriver,正在尝试使用下面提到的方法单击“”网站中“演示站点”选项卡中的“电子商务演示站点”。但无法点击它。请在这个问题上帮助我 代码1: WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.linkText("E-Commerce Demo Site")))); driver.findElement

正在尝试使用下面提到的方法单击“”网站中“演示站点”选项卡中的“电子商务演示站点”。但无法点击它。请在这个问题上帮助我

代码1:

 WebDriverWait wait = new WebDriverWait(driver, 10);
  wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.linkText("E-Commerce Demo Site"))));
  driver.findElement(By.linkText("E-Commerce Demo Site")).click();
代码2:

driver.findElement(By.cssSelector("#main-nav > li.menu-item.menu-item-type-custom.menu-item-object-custom.menu-item-has-children.menu-item-17611.dt-mega-menu.mega-auto-width.mega-column-1.has-children > ul > li.menu-item.menu-item-type-custom.menu-item-object-custom.menu-item-21575.dt-mega-parent.wf-1.first.level-arrows-on")).click();
代码3:

WebElement subNav = driver.findElement(By.className("sub-nav"));
List < WebElement > subNavValues = subNav.findElements(By.tagName("li"));

subNavValues.get(0).click();
WebElement subNav=driver.findElement(By.className(“sub-nav”);
ListsubNavValues=subNav.findElements(按.tagName(“li”));
subNavValues.get(0).单击();
您可以尝试以下方法: driver.findElement(By.xpath(“//*///span[contains(text(),”电子商务演示 单击()

  • 您需要移动到“演示站点”范围。必须使用Actions类,才能使用函数
    moveToElement()
    移动到此元素。对于元素,使用文本“DEMO SITES”搜索跨度

  • 等待子菜单显示。在元素ul上使用webdriver wait class='sub-nav'<代码>新WebDriverWait(驱动程序,3)。直到(预期条件。可见(子菜单webelement))。

  • 然后单击“电子商务演示站点”链接。与文本在同一范围内


  • 您可以找出确切的语法。

    在最大化窗口后,请尝试以下内容

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    WebElement elem = driver.findElement(By.xpath("//nav[@id='navigation']/ul/li[9]/a/span"));
    Actions action = new Actions(driver);
    action.moveToElement(elem).build().perform();
    

    这对我很有用。

    试试这样的方法,它对我很有用:

    @Test
    public void qaToolsNavigation() {
        Actions action = new Actions(driver);
        By demoSitesMenuItem = By.xpath("//span[text()='DEMO SITES']");
        By eCommerceSubMenuItem = By.xpath("(//span[text()='E-Commerce Demo Site']/..)[1]");
        driver.get("http://toolsqa.com/");
        waitForVisibility(demoSitesMenuItem, 10);
        action.moveToElement(driver.findElement(demoSitesMenuItem)).build().perform();
        waitForVisibility(eCommerceSubMenuItem, 10);
        driver.findElement(eCommerceSubMenuItem).click();
    }
    
    private void waitForVisibility(By locator, int timeToWait) {
        WebDriverWait wait = new WebDriverWait(driver, timeToWait);
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    }
    
    然后使用以下任一XPath单击子菜单:

    1.“//span[contains(text(),'E-Commerce Demo Site')”

    2.“//a[@href=''”


    我在使用上述代码时遇到以下错误:没有这样的元素:无法找到元素:{“方法”:“链接文本”,“选择器”:“演示站点”}有一些复制粘贴错误。使用以下代码。它应该工作:ac=新动作(dr);ac.MoveToElement(dr.findelelement(By.LinkText(“演示站点”)).Perform();
         Actions ac;
     ac = new Actions(dr);
    ac.MoveToElement(dr.FindElement(By.LinkText("DEMOSITES"))).Perform();
    
    dr.findelement(By.xpath(xpath)).click();