如何访问第二个<;p>;在selenium(Python)中?
我是Python和Selenium的新手。我有以下代码:如何访问第二个<;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克 我想访问第二个标记并获取其值
<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)')