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
获取父元素包含特定文本的元素的XPath_Xpath_Selenium Webdriver - Fatal编程技术网

获取父元素包含特定文本的元素的XPath

获取父元素包含特定文本的元素的XPath,xpath,selenium-webdriver,Xpath,Selenium Webdriver,我的代码如下所示,我想点击“查看详细信息”,但标记p包含文本“都柏林” 如何获取xpath 都柏林 我假设这就是html的外观: <div class="office-name"> <p class="">Dublin <a target="abc" >View map</a> <a href="">View details</a> </p> <

我的代码如下所示,我想点击“查看详细信息”,但标记p包含文本“都柏林” 如何获取xpath


都柏林


我假设这就是html的外观:

<div class="office-name">
    <p class="">Dublin
        <a target="abc" >View map</a>
        <a href="">View details</a>
    </p>
    <p class="abc">
        <a target="abc" >View map</a>
        <a href="">View details</a>
    </p>
</div>
好的,对不起,我误解了你的HTML。此选择器将工作,但我不知道是否支持以下

//div[@class='office-name']/p[contains(text(), 'Dublin')]/following::p/a[contains(text(),'View details')]
试一试


不,HTML看起来就像我粘贴的那样,所以我可以通过下面的xpath//div[@class=''office-name]/p/a[contains(text(),'View details')]查看详细信息,但我想要的是它还应该检查div[@class=''office-name]/p[是否有都柏林文本]谢谢Paul,这可能会起作用,但我使用的框架不支持使用以下同级::还有其他方法吗?您可以尝试
//div[@class=“office name”][p[contains(text(),'Dublin')]/p[@class=“abc”][1]/a[contains(text(),'View details')]
如果“Dublin”是变量,如何执行描述的操作(假设我在运行时添加此元素,每次它都有不同的文本)?在使用页面工厂时,不可能使用“p[contains(text(),'“+dublin_var+”)…”
//div[@class='office-name']/p[contains(text(), 'Dublin')]/following::p/a[contains(text(),'View details')]
//p[contains(text(), 'Dublin')]
 /following-sibling::p[@class="abc"][1]
     /a[contains(text(),'View details')]