2016-12-19 76 views
0

我有這個地址,「6425 Fire Creek Trl」。我正在自動化這個過程。我無法弄清楚並請求您的協助是如何告訴Selenium點擊搜索結果中顯示的第一個搜索結果(許可證編號B13-1351)。我搜索了頁面源代碼,但找不到任何進展。點擊第一個值

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.wait import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
import csv 
import os 


driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe") 
chrome = driver.get('https://etrakit.friscotexas.gov/Search/permit.aspx') 

wait = WebDriverWait(driver, 10) 

with open('C:/Users/.csv','r') as f: 
addresses = f.readlines() 

for address in addresses: 
    driver.find_element_by_css_selector('#cplMain_txtSearchString').clear()  
    driver.find_element_by_css_selector('#cplMain_txtSearchString').send_keys(address) 
    driver.find_element_by_css_selector('#cplMain_btnSearch').click() 

    table = wait.until(EC.visibility_of_element_located((By.ID, "ctl00_cplMain_rgSearchRslts_ctl00"))) 

回答

2

找到下表元素的tbody第一tr元素:

first_row = table.find_element_by_css_selector("tbody tr.rgRow") 
first_row.click() 

(對我的作品)

+0

感謝Alexce,偉大工程!!!!! –