0
我試圖做從http://www.gps-coordinates.net/使用硒刮網絡,我有2個方面的問題。硒處理彈出和谷歌自動完成
- Google自動完成使我無法點擊'獲取 座標'按鈕。我試圖解決它,但有時它仍然 不起作用。 (消息:元素在點(280,17.800003051757812)不可點擊,其他元素會收到點擊)
- 彈出表示沒有可用的結果,但仍無法處理彈出窗口。
`
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import openpyxl
import xlsxwriter
import pyperclip
driver = ""
def setup():
global driver
driver = webdriver.Firefox()
driver.get("http://www.gps-coordinates.net/")
assert 'Google Map' in driver.title
def sele(address):
setup()
global driver
query = driver.find_element_by_id('address')
query.clear()
query.send_keys(address)
query.send_keys(Keys.RETURN)
driver.implicitly_wait(0.7)
query.send_keys(Keys.DOWN) #To solve in case there is autocomplete by Google
query.send_keys(Keys.RETURN)
button = driver.find_element_by_xpath("//*[@id='wrap']/div[2]/div[4]/div[1]/form[1]/div[2]/div/button")
button.click()
driver.implicitly_wait(0.7)
if EC.alert_is_present(): #If there is a popup, that means there is no result for the geocoding
alert=driver.switch_to_alert()
alert.accept()
latlong = ['Fail','Fail']
return latlong
else:
latraw = driver.find_element_by_id('latitude')
longraw = river.find_element_by_id('longitude')
latraw.send_keys(Keys.CONTROL,'A')
latraw.send_keys(Keys.CONTROL,'C')
lat = pyperclip.paste()
latraw.clear()
longraw.send_keys(Keys.CONTROL,'A')
longraw.send_keys(Keys.CONTROL,'C')
long = pyperclip.paste()
latraw.clear()
return [lat,long]