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
如何访问第二个<;p>;在selenium(Python)中?_Python_Selenium_Tags - Fatal编程技术网

如何访问第二个<;p>;在selenium(Python)中?

如何访问第二个<;p>;在selenium(Python)中?,python,selenium,tags,Python,Selenium,Tags,我是Python和Selenium的新手。我有以下代码: <div class="Product_ProductInfo__23DMi"> <p style="font-weight: bold;">4.50</p> <p>Bread</p> <p>390 g</p> </div> 4.50 面包 390克 我想访问第二个标记并获取其值

我是Python和Selenium的新手。我有以下代码:

<div class="Product_ProductInfo__23DMi">
   <p style="font-weight: bold;">4.50</p>
   <p>Bread</p>
   <p>390 g</p>
</div>


4.50

面包

390克

我想访问第二个
标记并获取其值(我的意思是
面包

对于第一个
标记,我使用了:

self.driver.find_element_by_xpath('//div[@class=“Product\u ProductInfo\uu 23DMi”]/p')

但是我不知道怎么去另一个


谢谢。

您可以使用
find\u elements\u by\u css\u selector()

a = self.webdriver.find_element_by_css_selector('div[class="Product_ProductInfo__23DMi"]')
second_p = a.find_elements_by_css_selector('p')[1]

您可以使用
:nth-of-type()
(索引以1开头),这就是您可以说的css属性

a = self.webdriver.find_element_by_css_selector('div[class="Product_ProductInfo__23DMi"] > p:nth-of-type(2)')