WebDriver can't find element by xpath using Java

后端 未结 6 1810
甜味超标
甜味超标 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:33

    @user729076: The xpath "//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input" you wrote for google text field is not right. The HTML for google text field is as follows:

    
    

    Based on the above HTML, you can use simply id or xpath as below: By id:

    driver.findElement(By.id("gbqfq")).sendKeys("some text");
    

    By xpath:

    driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys("some text");
    

提交回复
热议问题