Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Firefox webdrive, using Python, scrolling in div

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?

like image 949
Ajay Moganti Avatar asked Oct 04 '14 03:10

Ajay Moganti


1 Answers

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.

like image 176
falsetru Avatar answered Oct 26 '22 23:10

falsetru