1

i was trying to scrolling down to a paticular element in python , but it is not working.any Suggesstion to improve!

Loc_Hours =self.driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[5]/div[1]/div[1]/div[1]/div[2]/div[1]/p[1]")
self.driver.execute_script("return arguments[0].scrollIntoView();", Loc_Hours)
Loc_Hours.text()
self.driver.execute_script("window.scrollBy(0, -150);")
Andersson
  • 51,635
  • 17
  • 77
  • 129
koushick
  • 497
  • 2
  • 8
  • 30

3 Answers3

2

Can you please try this:

from selenium.webdriver.common.action_chains import ActionChains

Loc_Hours = self.driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[5]/div[1]/div[1]/div[1]/div[2]/div[1]/p[1]")
ActionChains(self.driver).move_to_element(Loc_Hours)).perform()
Nihal
  • 5,262
  • 7
  • 23
  • 41
  • Loc_Hours is in the Middle of the page, i need to scroll down to that area and get the text. that is my Query. @Nihal – koushick Dec 18 '18 at 08:26
  • did you try my answer? can please tell me if that is working for scrolling or not? – Nihal Dec 18 '18 at 08:29
  • Am Getting ElementNotVisibleException ! @Nihal – koushick Dec 18 '18 at 08:32
  • `Loc_Hours = self.driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[5]/div[1]/div[1]/div[1]/div[2]/div[1]/p[1]")` are you getting error in this line? because i know that `ActionChains(self.driver).move_to_element(Loc_Hours)).perform()` will work – Nihal Dec 18 '18 at 09:34
  • 1
    ok you got your answer from comments. good. You should post that as your answer and accept it. for the reference to other who all are having the same question – Nihal Dec 18 '18 at 09:35
  • Down i have Posted his answer.@Nihal – koushick Dec 18 '18 at 10:05
  • don't use `@Andersson Answer Worked out. Thanks Man ! Am Considering`. in your answer. post that in comment of your answer. and just write this works for me. because it will be consider as thank you answer for the reviews, or may get flagged. – Nihal Dec 18 '18 at 10:10
0

This Worked out For Me! Just Try This if you have Doubt.

print(Loc_Hours.get_attribute('textContent'))
koushick
  • 497
  • 2
  • 8
  • 30
0

This should work:

driver.execute_script("arguments[0].scrollIntoView()", Loc_Hours);
Alichino
  • 1,668
  • 2
  • 16
  • 25
  • No, it is not Working , First i gone through this method only @Alichino after that i became stressed for finding a soultion and came here and found a Solution – koushick Dec 19 '18 at 13:13