我正在尝试将输入(zipcode)输入到商店定位器中。
zipcode = input("What zip code would you like to search? ")
driver = webdriver.Firefox()
driver.get('http://www2.dollargeneral.com/About-Us/pages/storelocator.aspx')
driver.maximize_window()
print "page accesses"
inputElement = driver.find_element_by_xpath("//*[@id='address']")
inputElement.send_key(zipcode)
inputElement.send_keys(Keys.ENTER)
我也在WebDriver中尝试了多种不同的select_by
方法。任何人都可以朝着正确的方向推动我吗?我过去经常使用过硒,难道这在这个特定的网站上是不可能的吗?谢谢你的帮助!
smit9234是正确的 - 你需要切换帧。这有效:
from selenium import webdriver
zipcode = "91307" #input("What zip code would you like to search? ")
driver = webdriver.Chrome()
driver.get('http://www2.dollargeneral.com/About-Us/pages/storelocator.aspx')
driver.switch_to_frame("StoreLocator")
el = driver.find_element_by_id("address")
el.send_keys(zipcode)
要在商店定位器搜索框中发送字符序列(zipcode),您需要:
click()
send_keys()
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.binary_location = r'C:\Program Files\Firefox Nightly\firefox.exe'
driver = webdriver.Firefox(firefox_options=options, executable_path=r'C:\WebDrivers\GeckoDriver\geckodriver-v0.20.1-win64\geckodriver.exe')
driver.get("http://www2.dollargeneral.com/About-Us/pages/storelocator.aspx")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"StoreLocator")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.closeBtn>img[src='images/dollargeneral_new_bubble_close.png']"))).click()
zipcode = input("What zip code would you like to search? ")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control#address"))).send_keys(zipcode)