【发布时间】:2019-10-09 01:46:31
【问题描述】:
我正在尝试使用 python 和 selenium 来单击一个元素而没有成功,就像我想单击按钮元素时一样。
python --version
Python 2.7.16
print selenium.__version__
3.141.0
chromedriver --version
ChromeDriver 2.36
chromium-browser --version
Chromium 65.0.3325.181
这是标签:
<a data-fblog="the_button" href="javascript:" id="the_btn" class="the_btn" title="Goto">Goto</a>
(显然没有定义为按钮)
这是负责点击该标签的python部分:
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
driver = webdriver.Chrome('PATHTOCRHROMEDRIVER/chromedriver',options=chrome_options)
driver.get('https://www.urltogetinfo.com')
try:
the_button = driver.find_element_by_id('the_btn')
the_button.click()
#Also tried these aproaches without sucess:
#the_button = driver.find_element_by_id('the_btn').send_keys(Keys.RETURN)
#the_button = driver.find_element_by_id('the_btn').send_keys(Keys.ENTER)
sleep(5)
except:
print("Problem clicking the button")
#would like to log the exception here
pass
我做错了什么?
【问题讨论】:
-
您是否尝试添加等待可点击或验证元素不在
IFRAME内? -
你检查过这个按钮是否存在于 iframe 中吗?