selenium - Unable to open href link in selenium python
问题描述
I have a array called accounts which gets all the href's i want, i then want to open each of these, i have tried the following code
accounts = self.driver.find_elements_by_xpath("//a[contains(@href, '/signin?')]")
for account in accounts:
self.driver.get(account)
time.sleep(3)
But returns
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'url' must be a string
(Session info: chrome=80.0.3987.132)
解决方案
您正在获取 Web 元素的列表,因此您需要首先href
从这些 Web 元素中获取属性,然后点击它们。
你可以这样做:
accounts = self.driver.find_elements_by_xpath("//a[contains(@href, '/signin?')]")
for account in accounts:
self.driver.get(account.get_attribute("href"))
time.sleep(3)
推荐阅读
- python - 如何删除 Django ModelForm 上的字段?
- ruby - Ruby RSpec 只为一个上下文定义 before/after 钩子
- sphinx - 用于浮点值的 Sphinx MVA
- c# - WPF 模拟按键按下事件未按预期工作
- java - 无法编译项目:lombok 创建的 Getter 不起作用
- android - Android新添加的代码控件由原来的XML控件改变
- parse-platform - 解析服务器查询对象不返回任何结果
- windows - WSUS 多服务器自动化 - 如何确定每个 KB 名称的 Windows 版本?
- c# - 运行时 MissingMethodException
- kdb - KDB:功能优化