WebDriver can't find element by xpath using Java

后端 未结 6 1878
甜味超标
甜味超标 2021-01-21 22:52

The following is the snippet of WebDriver code using Java:

        WebDriver driver = new FirefoxDriver();
        driver.get(\"http://www.google.pl/\");
                


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 23:32

    Your xpath expression:

    WebElement query = driver.findElement(By.xpath("//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input"));

    looks correct but if you still are facing the issue please check the correctness of xpath again. If it fails again increase the time for Wait as:

    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    

    or you can use explicit wait for the specific element as below:

    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input")));
    

提交回复
热议问题