Selenium Webdriver中的click命令不起作用 [英] click command in selenium webdriver does not work

查看:1080
本文介绍了Selenium Webdriver中的click命令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近刚刚将我的Selenium IDE代码导出到了Selenium Web驱动程序.我发现很多在IDE中可用的命令要么无法运行,要么硒Web驱动程序声称根本不支持.到目前为止,我一次只解决了这些问题,这不尽人意...

I have just recently done an export of my selenium IDE code to selenium web driver. I have found that a lot of the commands that worked in IDE either fail to work or selenium web driver claims to not support at all. So far I've been tackling these issues one at a time which is less than ideal...

目前,我正在研究为什么以前在selenium IDE中无法使用Web驱动程序单击按钮的原因.我的浏览器是FF 13,我的操作系统是Ubuntu.

Currently I'm working on finding out why clicking on a button does not work with web driver while it had previously worked in selenium IDE. My browser is FF 13 and my OS is Ubuntu.

代码段

WebElement loginButton = driver.findElement(By.name("submit"));
loginButton.click();

我以前尝试过

driver.findElement(By.name("submit")).click();

但是上述行也失败了.该元素正在被选择,但是它并没有按照我的意愿登录.我发现其他页面也有类似的问题,但是它们的问题似乎是Internet Explorer而不是Firefox.我什至不想考虑IE会给我带来的麻烦.

however the above line failed as well. The element is getting selected, however it does not log us in as I would like. I found other pages with similar problems, but their problem seemed to be with Internet Explorer not Firefox. I don't even want to think about the problems IE will give me down the road.

谢谢

P.S. 在不丢失我编写的所有测试的情况下,从selenium IDE迁移到Selenium Webdriver的更好方法的技巧也可以解决此问题.

P.S. A tip on a better way to migrate from selenium IDE to Selenium Webdriver without losing all the tests I've written could solve this issue as well.

推荐答案

如果您确定该元素存在,则可以尝试模拟点击-如果.Click()不起作用

If you know for sure that the element is present, you could try this to simulate the click - if .Click() isn't working

driver.findElement(By.name("submit")).sendKeys(Keys.RETURN);

driver.findElement(By.name("submit")).sendKeys(Keys.ENTER);

这篇关于Selenium Webdriver中的click命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆