我想在下面的html代码中找到“ 160528”元素:
<td class="calCell">
<div id="cal1">
<div align="center">
<table id="table1">
<tbody>
<tr></tr>
<td>
<a id="160528"></a>
</td>
</tbody>
</table>
</div>
</div>
</td>
我所做的是:
calCell = driver.find_element_by_class_name('calCell')
cal1 = calCell.find_element_by_id('cal1')
table1 = cal1.find_element_by_id('table1')
程序将抱怨“无法定位元素”,但是table1确实存在。
有没有人可以分享一些关于如何定位160528的信息?除了逐个子元素化之外,还有其他更简单的方法吗?
搜索时该表可能不存在。添加一个等待:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
table1 = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".calCell #cal1 #table1")))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句