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 seleniu
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);
or
driver.findElement(By.name("submit")).sendKeys(Keys.ENTER);
WebElement.click()
click is found to be not working if the page is zoomed in or out.
I had my page zoomed out to 85%.
If you reset the page zooming in browser using (ctrl
+ +
and ctrl
+ -
) to 100%, clicks will start working.
Issue was found with chrome version 86.0.4240.111
A major thing to watch out for is whether a button is Enabled or not. You can still click them and nothing will fall over and the element is there but it is not ready to be clicked on so just doesnt do anything.
I've been using webdriver and its taken me most of the day to figure this out!
The following method seems to work reliably (in my environment for one button!)
private void TryClick(By selector)
{
var wait = WaitUpTo(TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementIsVisible((selector)));
//really important bit!
WaitUpTo(TimeSpan.FromSeconds(5))
.Until(d => element.Enabled);
element.Click();
}
you use it something like
TryClick(By.XPath("//button[contains(.//*,'Some Text')]"));