Select an element by the text it contains with Selenium Webdriver

前端 未结 2 908
情深已故
情深已故 2021-01-19 07:09

I\'ve jjust started off with Selenium Webdriver and I\'ve hit an issuee straight away involving the buttons I\'m trying to select/click all have no IDs and share the same cl

相关标签:
2条回答
  • 2021-01-19 07:32

    Fairly easy if you use xpath. if it has unique text your xpath should look like something like this

    //button[.='xyz']
    

    So, here "." points to the parent in HTML hierarchy and just look for text

    0 讨论(0)
  • 2021-01-19 07:33

    You can find the link by the visible text.

    IWebElement XyzLink= _browser.FindElement(By.LinkText("xyz"));

    Also you can locate the link by partial link text as follows,

    IWebElement XyzPartialLink= _browser.FindElement(By.PartialLinkText("XYZ"));

    For example this will locate a link element which contains 'XYZ' in its text.

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