我有这个地址,“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")))
答案 0 :(得分:2)
找到表格元素tr
下的第一个tbody
元素:
first_row = table.find_element_by_css_selector("tbody tr.rgRow")
first_row.click()
(适合我)