Selenium WebDriver findElement(By.xpath()) not working for me

后端 未结 8 1498
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 21:34

I\'ve been through the xpath tutorials and checked many other posts, hence I\'m not sure what I\'m missing. I\'m simply trying to find the following element by xpath:

相关标签:
8条回答
  • 2020-12-17 22:10

    You haven't specified what kind of html element you are trying to do an absolute xpath search on. In your case, it's the input element.

    Try this:

    element = findElement(By.xpath("//input[@class='t-TextBox' and @type='email' and @test-    
    id='test-username']");
    
    0 讨论(0)
  • 2020-12-17 22:12

    Correct Xpath syntax is like:

    //tagname[@value='name']
    

    So you should write something like this:

    findElement(By.xpath("//input[@test-id='test-username']"));
    
    0 讨论(0)
  • 2020-12-17 22:19

    your syntax is completely wrong....you need to give findelement to the driver

    i.e your code will be :

    WebDriver driver = new FirefoxDriver();
    WebeElement element ;
    
    element = driver.findElement(By.xpath("//[@test-id='test-username']"); 
    

    // your xpath is: "//[@test-id='test-username']"

    i suggest try this :"//*[@test-id='test-username']"

    0 讨论(0)
  • 2020-12-17 22:20

    You should add the tag name in the xpath, like:

    element = findElement(By.xpath("//input[@test-id='test-username']");
    
    0 讨论(0)
  • 2020-12-17 22:21

    You missed the closing parenthesis at the end:

    element = findElement(By.xpath("//[@test-id='test-username']"));
    
    0 讨论(0)
  • 2020-12-17 22:26
    element = findElement(By.xpath("//*[@test-id='test-username']");
    element = findElement(By.xpath("//input[@test-id='test-username']");
    

    (*) - any tagname

    0 讨论(0)
提交回复
热议问题