I am using the following script
from selenium import webdriver
import time
import urllib.parse
browser = webdriver.Chrome()
with open("google-search-terms.adoc") as fin:
for line_no, line in enumerate(fin):
line = line.strip()
query = urllib.parse.urlencode({'q': line})
browser.execute_script(
f"window.open('https://www.google.com/search?{query}');")
for x in range(len(browser.window_handles)):
browser.switch_to.window(browser.window_handles[x])
time.sleep(3)
try:
browser.find_elements_by_xpath(
"//*[@id='rso']/div/div/div/a/div/cite[contains(text(),'amazon')]").click()
except:
pass
The input file google-search-terms.adoc
contains:
The Effective Executive by Peter Drucker
The Functions of the Executive
It open multiple tabs containing search result of the texts from input file. It loop over the tabs every 3 seconds. However, it is not clicking the expected search results?
What is wrong here?