Issue
I am using selenium, python, and javascript to extract data from the following link:
https://www.google.co.in/search?q=Fortis+Escorts+Heart+Institute+%26+Research+Centre,+Okhla+Road,+Opp+Holy+Family+Hospital,+New+Friends+Colony,+New+Delhi,+Delhi+110025&ludocid=8685206163378021720#lrd=0x390ce4759f47e68d:0x78880cfd492e2558,1
When I execute the following script the main window is scrolled and not the pop up window (an ajax window).
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
I want to scroll the pop up window and not the main window. Any help is appreciated.
For exiting the loop in the main browser window, I am using the following logic:
while (num_clicks>=0 and end_doc==0):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3)
num_clicks = num_clicks-1
x = driver.execute_script("return pageYOffset")
if x==y:
end_doc = 1
y = x
Is there a way to use a similar logic to exit from the sub window.
Solution
Scroll into view of the last review in the list, repeat:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.google.co.in/search?q=Fortis+Escorts+Heart+Institute+%26+Research+Centre,+Okhla+Road,+Opp+Holy+Family+Hospital,+New+Friends+Colony,+New+Delhi,+Delhi+110025&ludocid=8685206163378021720#lrd=0x390ce4759f47e68d:0x78880cfd492e2558,1")
while True: # TODO: decide on when to stop the loop
reviews = driver.find_elements_by_css_selector("._ju")
driver.execute_script("arguments[0].scrollIntoView();", reviews[-1])
The code is working for me, but I've left for you to decide on the endless loop exit condition.
Answered By - alecxe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.