(I\'ve looked at many other similar posts on SO and have unfortunately not been able to solve this problem, so here goes...)
I\'m using Selenium WebDriver (C# implementa
try this..
WebElement hiddenWebElement =d.findElement(By.xpath(xpath));
((JavascriptExecutor)d).executeScript("arguments[0].click()",hiddenWebElement);
May be you need to set Enable Native Events to "true" when you are running it on IE and if you want to run the same code in FF and Chrome,then you need to enable Native Events to "true" in those Browsers too.
You can do that when you are setting the Browser on which you wish to run.
I had this problem. I can't remember the post where I found the resolution but I found that the following worked for me:
On a button:
var navButton = driver.FindElement(By.Id("NavButton"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", navButton);
Works every time.
I was also having problems sending the click event to a table row. Sometimes the .Click() would actually send the event to the row above (we have a horribly complicated table structure which has a hidden radio button within it which is also not clickable with Selenium). The above hack wouldn't work with cells that were accessible through a FindElement.
In the end the only thing that worked was to select the image within that row and send the click to that.
var img = driver.FindElement(By.Id("fim{4C3DE9FA-45B0-40E0-BD95-9EE0374EA38A}"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", img);
Hope that helps.
Use FindElement(By.CSSSelector("'CSSPath'"))
; If you have any CSS applied to the button, its more consistent alternatively write other multiple statements to find the element with alternative means such as ID,tag or so with the WebDriverWait
Method
I see multiple solution here, but i thought I would share what worked for me in case anyone else out there needed a different approach. I had a similar problem, for me the solution was as simple as clicking using a different method
For example
btn.Sendkeys(Keys.Enter);
Try code -
driver.FindElement(By.Id("btn")).sendkeys("\n");