Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium webdriver:单击“不在python中工作”_Python_Selenium - Fatal编程技术网

Selenium webdriver:单击“不在python中工作”

Selenium webdriver:单击“不在python中工作”,python,selenium,Python,Selenium,我想先单击表格的链接,其中包含文本A218012216 表/链接代码似乎隐藏在JS中。 我尝试了几种方法,但都没有成功 这是我目前的代码: import time from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys from selenium.webdriver.sup

我想先单击表格的链接,其中包含文本
A218012216

表/链接代码似乎隐藏在JS中。
我尝试了几种方法,但都没有成功

这是我目前的代码:

import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
url0 ="https://ccrecordse.tarrantcounty.com/AssumedNames/SearchEntry.aspx"
driver = webdriver.Chrome(executable_path="D:\Python\chromedriver.exe")
driver.get(url0)
time.sleep(3)
#fill the form # select by visible text
selectStart = driver.find_element_by_id('x:11265151.0:mkr:3')
selectStart.send_keys('09/05/2019')
selectEnd = driver.find_element_by_id('x:1246303050.0:mkr:3')
selectEnd.send_keys('09/05/2019')
#submit the form
driver.find_element_by_id("cphNoMargin_SearchButtons2_btnSearch__5").click()
time.sleep(3)
driver.find_element_by_link_text('A218012216').click()

如何获取该信息?

问题是,您试图在非
标记链接的元素上使用
通过链接查找元素\u文本
。\u文本仅用于
标记

在我的解决方案中,您将看到我正在使用
WebDriverWait
这是selenium中的最佳实践

另外,我使用了XPath定位器和
text()=the_text
注意
the_text
将需要随着日期的变化而变化(您正在搜索未来日期
09/05/2019
,因此它显示了文本将变化的当前日期…)

解决方案:

import time
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

url0 ="https://ccrecordse.tarrantcounty.com/AssumedNames/SearchEntry.aspx"

driver = webdriver.Chrome(executable_path=r"D:\Python\chromedriver.exe")

driver.get(url0)
time.sleep(3)
#fill the form # select by visible text
selectStart = driver.find_element_by_id('x:11265151.0:mkr:3')
selectStart.send_keys('02/19/2019')
selectEnd = driver.find_element_by_id('x:1246303050.0:mkr:3')
selectEnd.send_keys('02/19/2019')
#submit the form
driver.find_element_by_id("cphNoMargin_SearchButtons2_btnSearch__5").click()
the_text = "A219002410"
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='"+the_text +"']"))).click()

希望这对你有帮助

共享html或URL您需要共享html源代码以获得有价值的答案。URL在代码中。