Element is found in XPath Checker but not in Selenium

前端 未结 4 586
庸人自扰
庸人自扰 2021-01-14 18:29

I have the following XPath:

//div[contains(@id, \'box\')]/div/h4/small/a[contains(@href, \'google\')]/@href

When I try out this XPath in XP

相关标签:
4条回答
  • 2021-01-14 19:00

    You should write xpath first eg

    WebDriver_Object_name.findElement(By.xpath("...xpath...")).getAttribute("..Attri_name..");
    

    Here your WebDriver_Object_name might be selenium

    0 讨论(0)
  • 2021-01-14 19:18

    According to the API doc, it should be

    ...getAttribute("xpath=//div[contains....
    
    0 讨论(0)
  • 2021-01-14 19:19

    In Selenium RC: it needs to mention xpath as "xpath=//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href". So in your case, the code is as below:

    selenium.getAttribute("xpath=//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href");
    

    In Selenium WebDriver: the code is as below:

    driver.findElement(By.xpath("//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href")).getAttribute("The name of the attribute");
    
    0 讨论(0)
  • 2021-01-14 19:21

    Shouldn't that query string look like this (according to javadoc api)?

    "xpath=//div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href"
    
    0 讨论(0)
提交回复
热议问题