笔记一下学习的心得,selenium 如何定位到iframe? 可以通过id 或者name 进行定位 switch_to_frame(name_or_id_or_frame_element ) 例如: from selenium import webdriver 根据部分元素属性定位 driver.find_element_by_xpath ("//div[contains(@id, 'btn-attention')]") driver.find_element_by_xpath ("//div[starts-with(@id, 'btn-attention')]") driver.find_element_by_xpath ("//div[ends-with(@id, 'btn-attention')]") # 这个需要结尾是‘btn-attention’ contains(a, b) 如果a中含有字符串b,则返回true,否则返回false starts-with(a, b) 如果a是以字符串b开头,返回true,否则返回false ends-with(a, b) 如果a是以字符串b结尾,返回true,否则返回false 所以根据上述代码可以修改成: from selenium import webdriver driver.switch_to.frame(driver.find_element_by_xpath("//iframe[starts-with(@id, 'x-URS-iframe')]"))
|
|