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.
Generally 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: