javascript - 无法单击 selenium webdriver 中的链接

标签 javascript firefox selenium-webdriver

我正在尝试单击链接。但它显示元素未找到消息。这是我的 HTML 代码:
<a id="expTo" class="formblue_link padRight10 exportLinkActive" style="display: block; margin-left: -50px; margin-bottom: -20px;" href="javascript:;"> Export To</a>

我的代码是:

        `driver.findElement(By.linkText("Export To")).click();`

最佳答案

建议不要尝试通过按钮或项目文本查找元素。当页面仍处于开发阶段时,这可以很容易地更改,因此我建议使用按id点击而不是按文本

 driver.findElement(By.id("expTo")).click();

还有一种通过 css 点击的替代方法,例如:

 driver.findElement(By.cssSelector(".css-class-name"));

可以找到所有其他选择器 here

关于javascript - 无法单击 selenium webdriver 中的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39208588/

相关文章:

python - 尝试自动化浏览器时 Selenium 中的 ElementNotInteractableException

java - 定位元素和 getText() 值

javascript - 通过 ng-init 将变量注入(inject)到 Controller

javascript - Fabric.js 的撤消重做

php - 我在 Firefox 中的 php session 出了问题

python - 当我使用 Selenium Webdriver 时,Geckodriver 正在创建 rust_mozprofile 目录

Python webdriver 脚本可以从控制台运行,但不会作为 Upstart 服务启动

javascript - react /Redux/JavaScript : How to pass a callback in string format then in renderer make it work?

javascript - 类型错误 : Cannot read property 'form' of null angular

CSS 'text-shadow' 在 Firefox 中不工作