Warm tip: This article is reproduced from serverfault.com, please click

Selenium

发布于 2020-11-30 08:47:29

How to find article on website by h1 and p text like on image below?

I tried this, where I can found all articles and I don't know how to find this one with text in h1 and by text in p. And then I would like to click on this.

text = driver.find_elements_by_xpath("//article/div[contains(@class,'inner-article')]/h1")

enter image description here

Questioner
Filip
Viewed
0
PDHide 2020-11-30 18:07:14
text = driver.find_elements_by_xpath("//article/div[contains(@class,'inner-article')][h1/a[contains(text(),"Beanie")]][p/a[contains(text(),"Red")]]")

you can use above xpath, which will check whehter the parent element article/div has child elements h1/a and p/a with texts Beanie and Red respectively

in w3chool html editor is inside iframe so switch to iframe in your seelnium tests before tryng to find the element