如何为<span class =“ lbl ui_lbl_radio custom-control-description”>业务</span>构建xpath

时间:2019-01-09 06:44:20

标签: selenium-webdriver xpath webdriver

无法点击,错误是:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()='prpse1']"}

HTML:

<span class="lbl ui_lbl_radio custom-control-description">Business</span>

2 个答案:

答案 0 :(得分:0)

要单击文本为 Business 的元素,可以使用以下Locator Strategy

  • xpath

    //span[@class='lbl ui_lbl_radio custom-control-description' and text()='Business']
    

答案 1 :(得分:0)

要单击元素,可以使用CSS选择器方法,如下所示:

driver.findElement(By.cssSelector(“ span.lbl ui_lbl_radio custom-control-description”))。click();