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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With