填写搜索框时,搜索按钮不起作用

时间:2018-03-03 19:48:38

标签: python python-3.x selenium selenium-webdriver web-scraping

我在python中用selenium编写了一个刮刀,在搜索框中输入一个地址,然后按下搜索按钮。当我运行刮刀时,看起来它填充了地址,但当按下搜索按钮填充结果时,该网站显示.send_keys()。我哪里出错了?搜索地址嵌入在from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() wait = WebDriverWait(driver, 10) driver.get("replace with above address") wait.until(EC.presence_of_element_located((By.ID, "autocomplete"))).send_keys("5068 SW 141st Ave, Miramar, FL 33027") wait.until(EC.presence_of_element_located((By.ID, "map-search"))).click() driver.quit() 内以进行测试。提前感谢您的帮助。

网站地址:website

这是我的尝试:

iframe
是的,没有declare @startDate date, @endDate. select @startDate=min(ride_date), @endDate=max(ride_date) from rides declare @tempDate date=dateAdd(dd,-1,@startDate) declare @dateIntervals table(starDT dateTime, endDT dateTime) while(@tempDate<@endDate) begin insert into @dateIntervals values(cast(@tempDate as DateTime)+'05:00:00',cast(dateAdd(dd,1,@tempDate) as DateTime)+'05:00:00') select @tempDate=dateAdd(dd, 1,@tempDate) end select t1.startDT as d, SUM(ride_earnings+ride_tips) as total, COUNT(id) as ride_count from @dateIntervals t1 left join rides t2 on t2.ride_date>=t1.startDT and t2.ridetDate<t2.endDT GROUP by d order by total DESC ,所以我认为它会那么简单,但结果恰恰相反。

1 个答案:

答案 0 :(得分:1)

尝试更新您的脚本,如下所示:

wait.until(EC.presence_of_element_located((By.ID, "autocomplete"))).send_keys("5068 SW 141st Ave, Miramar, FL 33027")
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "pac-item"))).click()
wait.until(EC.presence_of_element_located((By.ID, "map-search"))).click()

这应该允许您在搜索结果之前确认您的选择(您要使用的地址)

更新

如果第一个建议不起作用,请尝试以下

input_address = wait.until(EC.presence_of_element_located((By.ID, "autocomplete")))
input_address.send_keys("5068 SW 141st Ave, Miramar, FL 33027")
suggestion = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "pac-item")))
input_address.send_keys(Keys.DOWN)
suggestion.click()
input_address.send_keys(Keys.RETURN)