硒铬驱动程序[JAVA]等待元素可用于ubuntu单击

时间:2020-09-27 20:30:49

标签: java testing selenium-webdriver selenium-chromedriver

对于ubuntu *,适用于相同应用程序的Eclipse IDE的代码似乎失败。 请指导,我做错了什么,我试图添加等待条件和线程睡眠,但似乎无济于事。

  WebElement nav= driver.findElement(By.xpath("//*[@id='navbarNav']/ul[1]/li[2]/a"));

System.out.println("RESULTS" +driver.getCurrentUrl());

WebDriverWait w= new WebDriverWait(driver, 200);
Thread.sleep(400);

w.until(ExpectedConditions.elementToBeClickable(nav));

Thread.sleep(400);
       nav.click();

错误

 Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: [[ChromeDriver: chrome on LINUX (726e7ea18ab0340298b4be9c717b370b)] -> xpath: //*[@id='navbarNav']/ul[1]/li[2]/a] (tried for 200 second(s) with 500 milliseconds interval)
  

HTML代码

<div class="collapse navbar-collapse style-scope app-shell" id="navbarNav">
                <ul class="app-nav navbar-nav mr-auto style-scope app-shell">
                    <li class="nav-item style-scope app-shell">
                        <a class="nav-link p-3 px-4 style-scope app-shell" href="/#/dashboard">Dashboard</a>
                    </li>
                    <li class="nav-item style-scope app-shell">
                        <a class="nav-link py-3 px-4 style-scope app-shell active" href="/#/trend-analysis/tag-search">TrendAnalysis</a>
                        <ul class="sub-nav d-flex flex-row flex-nowrap list-unstyled style-scope app-shell">
                            <li class="sub-nav-item style-scope app-shell">
                                <a class="sub-nav-link style-scope app-shell active" href="#/trend-analysis/tag-search">
                                    Trend Analysis
                                </a>
                            </li>
                            <li class="sub-nav-item style-scope app-shell">
                                <a class="sub-nav-link style-scope app-shell" href="#/trend-analysis/value-based-search">
                                    Value-Based Search
                                </a>
                            </li>
                  .....

0 个答案:

没有答案