嗨,我想抓取下图中选择的内容:
Image Code
我知道我可以使用以下代码来获取文本:
cell = driver.find_elements_by_xpath(".//*[@id='ip_selection1233880116name']")
print cell.text
但是我的问题是ip_selection1233880116name应该是动态的,因为每次从图像中看到它都会改变。
我该怎么办?
非常感谢你的帮助!!!!
最佳答案
使用contains可以只捕获所有数字都会改变的名称,对于单个元素,您还应该使用find_element
而不是find_elements
:
find_element_by_xpath("//*[contains(@id,'ip_selection') and contains(@id,'name')]")
您还可以根据浏览器使用“开始于”和“结束于”:
find_element_by_xpath("//*[starts-with(@id,'ip_selection') and ends-with(@id,'name')]")