Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Python 在Selenium中使用xpath获取正确的节点?_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python 在Selenium中使用xpath获取正确的节点?

Python 在Selenium中使用xpath获取正确的节点?,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,访问此 我想获得产品材料和保养详细信息 Shell: 70% polyester, 30% wool Lining: 100% polyester Dry-clean. 我试过下面提到的代码,但它不适合我 self.browser.find_element_by_xpath("//h6[@class='pdp-product-description-title']/p").text 标记是同级元素,而不是子元素。使用以下同级::p self.browser.find_element_by_x

访问此

我想获得
产品材料和保养
详细信息

Shell: 70% polyester, 30% wool
Lining: 100% polyester
Dry-clean.
我试过下面提到的代码,但它不适合我

self.browser.find_element_by_xpath("//h6[@class='pdp-product-description-title']/p").text

标记是同级元素,而不是子元素。使用
以下同级::p

self.browser.find_element_by_xpath("//h6[@class='pdp-product-description-title']/following-sibling::p").text
这样试试

xpath解释:-使用
标记和
文本
方法开始
xpath
,然后使用
下面的
关键字继续使用
标记

self.browser.find_element_by_xpath("//h6[contains(text(), 'Material & Care')]/following::p[@class='pdp-product-description-content']").text

使用带有
标记的索引

self.browser.find_element_by_xpath("//h6[contains(text(), 'Material & Care')]/following::p[1]").text

我对代码的解释对你有帮助吗?如果确实如此,请将此答案标记为
已接受
,如果已解决您的问题。