Selenium WebDriver can't find element by link text

前端 未结 5 1365
死守一世寂寞
死守一世寂寞 2021-01-04 09:44

I\'m trying to select an element that includes an anchor, but the text is buried in a paragraph inside of a div. Here\'s the HTML I\'m working with:



        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 10:03

    A CSS selector approach could definitely work here. Try:

    driver.findElement(By.CssSelector("a.item")).Click();
    

    This will not work if there are other anchors before this one of the class item. You can better specify the exact element if you do something like "#my_table > a.item" where my_table is the id of a table that the anchor is a child of.

提交回复
热议问题