WebDriver can't find element by xpath using Java

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

    In this case the XPath expression you want is:

    //html/body/center/form/table/tbody/tr/td[2]/div/input
    

    Or you could use this (a little more intuitive):

    //input[@title='Google Search']
    

    Keep in mind that if you will be identifying a lot of elements by XPath it would be advisable to become fluent in XPath, you could start here: Xpath Tutorial

    In the meantime, use Firefox and install the following plugins:

    Firebug

    FirePath or Firefinder

    These will help you easily identify valid XPath expressions to use for your website.

提交回复
热议问题