【发布时间】:2023-02-09 06:05:24
【问题描述】:
我正在使用以下 html 代码:
<table .... >
<tbody .... >
<tr style="cursor:hand" onclick="OpenSession ("xxxx", "yyyyy", "zzzz")">
...
</tr>
<tr style="cursor:hand" onclick="OpenSession ("aaaa", "bbbbb", "cccc")">
...
</tr>
</tbody
</table>
使用python的selenium库,我想点击tr标签。我写了以下代码:
tr_elements = driver.find_elements(By.TAG_NAME,value='tr')
for tr in tr_elements:
if tr.get_attribute('onclick'):
print(tr)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//tr[contains(@onclick, 'OpenSession ')]"))).click()
time.sleep(5)
运行此脚本时,出现以下错误:
<selenium.webdriver.remote.webelement.WebElement (session="96f27c0a-2870-4011-8668-abbbdab5bd2c", element="7a4f8c92-f571-471e-ad63-6c6113f17494")> selenium.common.exceptions.ElementNotInteractableException:消息:无法将元素滚动到视图中
【问题讨论】: