python - 如何在 python 中使用 webdriver 识别 http 链接的元素

标签 python selenium selenium-webdriver webdriver click

如何识别链接,我检查了如下元素:

<div class="vmKOT" role="navigation">
<a class="Ml68il" href="https://www.google.com" aria-label="Search" data-track-as="Welcome Header Search"></a>
<a class="WaidDw" href="https://mail.google.com" aria-label="Mail" data-track-as="Welcome Header Mail"></a>
<a class="a4KP9d" href="https://maps.google.com" aria-label="Maps" data-track-as="Welcome Header Maps"></a>
<a class="QJOPee" href="https://www.youtube.com" aria-label="YouTube" data-track-as="Welcome Header YouTube"></a>
</div>

我想识别类 WaidDwhref 并使用 python 单击它。

最佳答案

你可以试试

driver.find_element_by_class_name('WaidDw').click()

driver.find_element_by_xpath('//a[@href="https://mail.google.com" and @aria-label="Mail"]').click()

关于python - 如何在 python 中使用 webdriver 识别 http 链接的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42292272/

相关文章:

python - 将字符串转换为numpy.ndarray python

python - Python 中可选静态类型的现状?

java - DOM 中两个不同元素的 Xpath OR 条件

selenium - Selenium需要显示器吗

javascript - 这是 promise 错误吗? Selenium-webdriver 测试提交登录成功后找不到元素

python - 在 Python 中根据 Textblob 的极性获取正面和负面的单词(情感分析)

python - AWS Elasticsearch 错误 "[Errno 8] nodename nor servname provided, or not known."

java - 无法单击选项卡的子值,在 Selenium 中出现 'element not visible' 异常

python - 如何使用 Selenium Chrome Webdriver、Python 正确使用自定义配置文件

java - 如何防止 Selenium 3.0 (Geckodriver) 创建临时 Firefox 配置文件?