0

I am not familiar with both HTML and Xpath so I am not sure whether I specified my question correctly. I use Selenium to scrape some data from certain websites (link). I figured out, that for some reason name of the class I interested in differs from page to page, however, this class contains a child node that in its turn contains a button. This button has the same text inside for all pages ("aplikuj", since sometimes appear another button with "aplikuj" inside I decided to add some RegEx "^aplikuj$"). My question is: How can I find parent class name knowing that its child node contains a button with particular text inside ("^aplikuj$"). As on the image below, I am looking for the "col-box ego-box-tabs-border box-info" class name (which will differ from page to page).

enter image description here

Updated: I want to extract text inside of <p> tags of "col-box ego-box-tabs-border box-info" class

Nayana Chandran
  • 1,416
  • 1
  • 16
  • 30
  • I'm not familiar with `selenium` (any reason you didn't include its tag?), but if I understand your question correctly, you're probably looking for `//div[p/a="aplikuj"]/p/normalize-space(.//text())`. – Reino Jun 05 '21 at 21:16

1 Answers1

0

Based on this topic: XPath to select element based on childs child value

You can select the div element that its child node contains a button which have the text 'aplikuj' by this code:

//div[./p[./a[contains(text(), "aplikuj")]]]

then, you can extend the code above to get all the text of p element in that div by this code:

//div[./p[./a[contains(text(), "aplikuj")]]]/p//text()

invio
  • 28
  • 5