Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用div元素的类和文本构造XPath_Html_Xpath_Selenium Webdriver_Automation - Fatal编程技术网

Html 使用div元素的类和文本构造XPath

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, '

我试图构造一个相对的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, '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']