admin管理员组文章数量:1314292
I have a button who's code is as follows:
<input type="button" onclick="someFunction();" value="doSomething">
I am trying to click on this button in Selenium2. I manage to get the element, but the click() function does not work in Chrome.
I tried to do it on JavaScript directly, but it still doesn't work in Chrome.
It works if you click directly on the button, and it also works in Firefox.
Anyone has any idea on how to fix this?
Edit: I had forgotten the brackets in my example. They're present in the "real" code.
Edit2: The Selenium 2 code used to simulate the click is:
driver.findElement(By.tagName("input")).click();
Before somebody asks, there is no other tagName "input" in the page.
I have a button who's code is as follows:
<input type="button" onclick="someFunction();" value="doSomething">
I am trying to click on this button in Selenium2. I manage to get the element, but the click() function does not work in Chrome.
I tried to do it on JavaScript directly, but it still doesn't work in Chrome.
It works if you click directly on the button, and it also works in Firefox.
Anyone has any idea on how to fix this?
Edit: I had forgotten the brackets in my example. They're present in the "real" code.
Edit2: The Selenium 2 code used to simulate the click is:
driver.findElement(By.tagName("input")).click();
Before somebody asks, there is no other tagName "input" in the page.
Share Improve this question edited Aug 28, 2012 at 13:48 Stilltorik asked Aug 28, 2012 at 13:34 StilltorikStilltorik 1,6924 gold badges19 silver badges31 bronze badges 2- 2 @dystroy I can't imagine removing the semicolon would help. It still wouldn't be called, would it? – Waleed Khan Commented Aug 28, 2012 at 13:37
-
Try modifying your code to this:
<input type="button" onclick="someFunction();" value="doSomething" />
– Shmiddty Commented Aug 28, 2012 at 13:43
4 Answers
Reset to default 6Generally speaking, using inline attributes to define event handlers is a bad idea. Instead you should opt for binding event handlers using JavaScript so that your content (HTML) and functionality (JavaScript) are separated.
However, the problem seems to be that you're not actually calling the function. Change it to:
<input type="button" onclick="someFunction();" value="doSomething">
i think you have to use function name with function brackets()
like this input type="button" onclick="someFunction();" value="doSomething"
i hope this will help you
Try like this, or even better put javascript in separate file:
<input type="button" value="doSomething" id="someFuncBtn">
<script type="text/javascript">
$(document).ready(function () {
$('#someFuncBtn').on('click', function(){
someFunction();
});
});
</script>
I realised that it was a problem with the click, that works a bit oddly sometimes. It works better this way:
driver.findElements(By.tagName("input")).get(0).click();
Even though it still fails "sometimes". I still have no idea why though.
本文标签: seleniumJavascript can39t click() on an ltinput typequotbuttonquotgt in ChromeStack Overflow
版权声明:本文标题:selenium - Javascript can't click() on an <input type="button"> in Chrome - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741963588a2407420.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论