0

i am using python selenium web driver. in my project i have two panes in a web site .

pane 1: ' tabindex="0" ' is the attribute of the pane 1.

in this pane like to find a CSS class '_1VzZY' with text '11/23/2020' inside this pane.

i should scroll up to the top till i find this CSS class with its matching value '11/23/2020'.

pane 2: in this pane ' #pane-side ' id is the id for the pane 2.

in this pane i should scroll down to find a custom text in it.

Problems i faced

the site loads its hidden pane contents (CSS part) only if i scrolled top or bottom , and if i didn't scroll, python cannot find the CSS class that i need.

Things i did

scrolling and finding date

  element = driver.find_element_by_xpath("//div[@class='_1VzZY' and text()='11/23/2020']")
  self.driver.execute_script("return arguments[0].scrollIntoView(true);", element)
  print("Scrolling")

find and click a title

    l = driver.find_element_by_xpath("//span[@title='Apple']")
    l.click()

Kind of Solution i need

task 1 i must scroll the 2nd pane first and search a particular Selector's text value (//span[@title='Apple']) and click it.

task 2 Now in the first pane (which is nearer to it) i should scroll up , till i find a class "._1VzZY" with value "11/23/2020".

task 1 should happen first after that task 2 should happen.

natasha
  • 41
  • 2

1 Answers1

0
for i in range(45):
    driver.execute_script("arguments[0].scrollBy(0, 500)")
    time.sleep(2)

you can use this to scroll down, i assume if you need to scroll up you can exchange the 0 and the 500. you can see how it scrolls and define the range() by that amount, that it is scrolled into vision. after that it should be visible and you can run the second command

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Timeler
  • 377
  • 1
  • 11
  • Python is sensitive to indentations. I've fixed it. Feel free to revert back in case I've broken the logic. – undetected Selenium Nov 30 '20 at 18:57
  • Oh thanks did not see it, ofc you are right. Would you agree with this solution? – Timeler Nov 30 '20 at 19:07
  • Syntactically I would have liked to see you using [WebDriverWait](https://stackoverflow.com/questions/59130200/selenium-wait-until-element-is-present-visible-and-interactable/59130336#59130336) instead of [`time.sleep()`](https://stackoverflow.com/questions/52603847/how-to-sleep-webdriver-in-python-for-milliseconds/52607451#52607451) – undetected Selenium Nov 30 '20 at 19:18
  • Understandable, might actually change that in the script im using myself if this works as well, since im a real fan of WebdriverWait rather than time.sleep() – Timeler Nov 30 '20 at 19:33