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);")
5
  • Loc_Hours.text() ?? Commented Dec 18, 2018 at 8:23
  • 1
    i hope you tried this stackoverflow.com/questions/12293158/… Commented Dec 18, 2018 at 8:24
  • @DebanjanB The Loc_Hours is in the Middle of the page, i need to scroll down to that area and get the text. Commented Dec 18, 2018 at 8:25
  • 1
    Try print(Loc_Hours.get_attribute('textContent')) Commented Dec 18, 2018 at 8:53
  • @Andersson Awesome Man! Thanks Commented Dec 18, 2018 at 9:34

3 Answers 3

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()
Sign up to request clarification or add additional context in comments.

7 Comments

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
did you try my answer? can please tell me if that is working for scrolling or not?
Am Getting ElementNotVisibleException ! @Nihal
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
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
|
0

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

print(Loc_Hours.get_attribute('textContent'))

Comments

0

This should work:

driver.execute_script("arguments[0].scrollIntoView()", Loc_Hours);

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.