python - Selenium 找到元素但未按应有的方式返回它
问题描述
我目前正在尝试使用Selenium
自动化一些繁琐的任务,这些任务涉及在网站中搜索某些文章,获取结果并将它们存储在文件中。
我的问题是,我正在这样做:
driver.find_element_by_link_text('text')
但是一个Selenium.webbrowser
对象正在返回,而不是我需要的链接。
我检查了页面的 HTML 代码,它看起来像
<a href = 'link.html'>text</a>
就像 selenium'doc'
所说的那样,它find_element_by_link_text
是设计用来处理的。
我的代码基本上如下:
driver.get(base_url)
search_box = driver.find_element_by_class_name('search-field')
search_box.send_keys('text i need to search', Keys.ENTER)
new_url = driver.find_element_by_link_text('text i need to find')
driver.get(new_url)
就像我提到的,new_url
它不是函数的有效参数get()
,因为它是一个对象。
解决方案
推荐阅读
- python - 无法同时使用 cv2 和 numpy 向图像添加蒙版
- github - 有没有办法自定义 GitHub 比较视图使用的差异算法?
- java - 当我重新运行程序时,为什么我的客户端不通过套接字向服务器发送数据?
- c++ - c ++将管道转换为逗号分隔
- ruby-on-rails - 如何在模块中的 Controller 中添加回调“after_create”?
- sql - 当免费配额不允许时,有什么方法可以在 bigquery 上运行大型查询的一部分?
- flutter - SliverOverlapAbsorber 能够接受多个条子
- python - 使用 Tkinter() 的按钮大小问题:python
- python-3.x - 异步循环函数停止
- django - 如何在 HTML 中单击按钮时更改 django 数据库中的值?