assume have list of terms:
a_lis = ['cat', 'dog', 'fish', 'worm', ..., 'ferret']
also, have website have search box:
how can pass , search each element of a_lis
search box?. after looking @ docs tried this:
from selenium import webdriver selenium.webdriver.common.keys import keys driver = webdriver.firefox() e in a_lis: driver.get("https:www.example.com") inputelement = driver.find_element_by_id("searchbox") inputelement.send_keys(e) inputelement.send_keys(keys.enter) driver.back()
however, not working. since pass string elements of a_lis
1 one without doing search. thus, how can pass each element 1 one , search search box?. in other words main objective search each string in a_lis individually search box.
update
i tried inside loop:
driver.execute_script("window.history.go(-1)")
nonetheless, did not worked.
i made example reference. go stack overflow, search each tag synchronously , close driver.
from selenium import webdriver selenium.webdriver.common.keys import keys time import sleep driver = webdriver.firefox() driver.get("http://stackoverflow.com/") query in ["java","python"]: driver.find_element_by_tag_name("input").send_keys(query) driver.find_element_by_tag_name("input").send_keys(keys.enter) # alternatively, find search button element , click it. # additional functionality here sleep(5) print "query link: ",driver.current_url driver.back() sleep(1) driver.quit()
- important things note, every iteration need return search page
driver.back()
, find search bar element againdriver.find_element
avoid stale element reference error.
Comments
Post a Comment