html - 如果它们都共享同一个 Div 类,我如何使用 Selenium 单击第三个 Div 类“链接”?
问题描述
我在 python 中使用 selenium。所有的 HTML 共享相同的 div 类“链接”。页面上共有七个链接,每个链接都具有相同的类和相同的名称。我想知道如果它们具有完全相同的名称 <div class"link"> 如何单击 web 元素
Selenium 与 python 使用 chrome webdriver。
<div class="aux">
<div class="links">
<a class="view" href="/pmc/articles/PMC1403861/">Summary</a>
<a class="view" href="/pmc/articles/PMC1403861/?report=classic&page=1">Page Browse</a>
<a class="view" href="/pmc/articles/PMC1403861/pdf/jeabehav00206-0003.pdf">PDF–1.6M</a>
<a class="view citationexporter" href="#" data-citationid="PMC1403861" role="button" aria-expanded="false" aria-haspopup="true">Citation</a>
</div>
</div>
解决方案
尝试使用以下语法 -
Python:
driver.find_element_by_xpath("//div[@class = 'links']/a[3]")).click();
爪哇:
driver.findElement(By.xpath("//div[@class = 'links']/a[3]")).click();
推荐阅读
- amazon-web-services - AccessDenied:无法使用 Cognito Identity 从 SDK 更新 CloudFormation 堆栈
- android - 如何在 android BLE 示例程序中获取从 BLE 接收的原始字节?
- javascript - 尝试在 Rails 中实现 js navbar 时未捕获的 TypeError
- android - 为系统应用添加 OPEN_APP_FEATURE
- python - 有没有办法将列表中的重复项分隔到另一个列表中
- node.js - 在Nodejs中使用内置宏读取Excel文件
- python - Keras:在自定义损失函数中访问信心
- git - 当它有特殊字符时,如何在 git pull 中使用密码作为环境变量?
- javascript - 复制的行重复输入
- python - 尝试为数据框的单元格着色然后将其转储为 html 并尝试保留单元格的样式时出现形状错误