6

I have been using python for a while, I want to save specific webpages which require prior login. Since this website uses javascript, I decided to use selenium for python with firefox webdrive. I was able to login. But the site requires me to accept EULA before I can access the required pages.

The problem is that I have to scroll down the entire text (with a seperate div scrollbar) before I can click accept. I am completely new to selenium and javascript.

The provided username and password are valid and I will change them once I get a solution.

dr = webdriver.Firefox()
dr.get("https://freida.ama-assn.org/Freida/user/programDetails.do?pgmNumber=1401611114")
dr.find_element_by_id("go_username").clear()
dr.find_element_by_id("go_username").send_keys("hajayd")
dr.find_element_by_id("go_password").clear()
dr.find_element_by_id("go_password").send_keys("123456")
dr.find_element_by_id("Image1").click()

dr.get("https://freida.ama-assn.org/Freida/eula.do")
# code to scroll down eula here
dr.find_element_by_id("agreeBtn").click()

dr.get("https://freida.ama-assn.org/Freida/user/programDetails.do?pgmNumber=1401611114")
# Final page I want to visit

Is it possible? Is there any other acceptable solution?

1
  • This is not duplicated question. This is not scrolling window to make a element visible, but scroll element's scrollbar. Commented Oct 5, 2014 at 5:30

1 Answer 1

11

You can use WebDriver.execute_script to execute javascript:

eula = dr.find_element_by_id('eulaFrame')
dr.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', eula)

Arguments (eula in above example) passed to javascript can be accessed using arguments[..].

Side note: If you use return in the javascript code, that value is available as the return value of the execute_script.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm not an expert in JavaScript nor Selenium, but arguments[0].scrollHeight can be changed for a number. For example with 0 it scrolls the div up
This snippet is to scrolldown the div. how to scrollup the div?
@user3121891, Please post a separated question.

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.