Html 使用div元素的类和文本构造XPath
我试图构造一个相对的xpath来与webdriver一起使用,但是我在获取任何我尝试使用的xpath时遇到了困难 我的Web元素:Html 使用div元素的类和文本构造XPath,html,xpath,selenium-webdriver,automation,Html,Xpath,Selenium Webdriver,Automation,我试图构造一个相对的xpath来与webdriver一起使用,但是我在获取任何我尝试使用的xpath时遇到了困难 我的Web元素: <div class="pa-PrimaryNavWidget-hyperlink" style="color: rgb(255, 255, 255); cursor: default; background-color: rgb(0, 173, 239);">Home</div> 我试过: //div[contains(@class, '
<div class="pa-PrimaryNavWidget-hyperlink" style="color: rgb(255, 255, 255); cursor: default; background-color: rgb(0, 173, 239);">Home</div>
我试过:
//div[contains(@class, 'pa-PrimaryNavWidget-hyperlink') and text()='Home']
//div[@class='pa-PrimaryNavWidget-hyperlink’ and text()='Home’]
//div[contains(.,'Home')]
试试这个
//div[@class="pa-PrimaryNavWidget-hyperlink" and text()='Home']
一般来说,xpath看起来不错。可能元素只是动态加载的。您是否尝试添加某种等待:
//div[@class="pa-PrimaryNavWidget-hyperlink" and text()='Home']