0

Here I want to get all the class = "result-row" which are above the "h4" tag, not the ones which are below "h4" tag.

enter image description here

My current code selects all of them:

section = driver.find_element_by_css_selector("[class='rows']")
result_rows = section.find_elements_by_css_selector("li.result-row")

so how can i get the desired result here?

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
Jaydeep
  • 775
  • 2
  • 8
  • 14
  • please use the snippet tool via [edit] to insert html so we can test with it. Also the url if possible. – QHarr Apr 25 '19 at 08:33

2 Answers2

1

You could try the following css which uses :not to filter out h4's general siblings based on class

li.result-row:not(h4.ban ~ li.result-row)

which might be simplified to:

.result-row:not(.ban ~ .result-row)
QHarr
  • 83,427
  • 12
  • 54
  • 101
0

If CSS is not obligatory, you can use XPath:

driver.find_element_by_xpath("//h4/previous-sibling::li")
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77