Selenium - 消息:没有这样的元素:无法找到元素
代码试验:
img_source = driver.find_element_by_css_selector('#root > div > div > div > div.MainFrameContainer > div > div > div > div > div > div > div.reader-area > div.reader-pages-container > div:nth-child(4) > img.f.e').get_attribute('src')
thumbs = driver.find_element_by_css_selector('div.thumbnail-storage')
driver.execute_script('arguments[0].scrollBy(arguments[0].scrollWidth, 0)', thumbs)
sleep(1)
pages = driver.find_elements_by_css_selector('#root > div > div > div > div.MainFrameContainer > div > div > div > div > div > div > div.reader-scrubber-container > div > div:nth-child(1) > h1 > div.pages-counter > span:nth-child(3)')
图像 url 的 Html:
<img crossorigin="anonymous" src="blob:https://1.mysite/7e50ba18-3f0f-4b8d-acff-5684d3d551bc" class="f e" style="width: 2000px; height: 2697px;">
运行机器人时告诉我错误:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#root > div > div > div > div.MainFrameContainer > div > div > div > div > div > div > div.reader-area > div.reader-pages-container > div:nth-child(4) > img.f.o"}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 HTML:
要提取 src 属性的值,您可以使用以下任一 定位器策略:
使用css_selector:
使用xpath:
理想情况下,您需要为 WebDriverWait /stackoverflow.com/a/50474905/7429447">visibility_of_element_ located() 并且您可以使用以下任一方法定位器策略:
使用CSS_SELECTOR:
使用XPATH:
注意:您必须添加以下导入:
As per the HTML:
To extract the value of the src attribute you can use either of the following locator strategies:
Using css_selector:
Using xpath:
Ideally you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
Using XPATH:
Note : You have to add the following imports :