Reputation: 510
I am using Selenium in Python for Internet explorer 11 to automate some tasks. I recently find out that the the click actions are not stable. Because everything work find in my computer, the button can be clicked. with for example:
driver.find_element_by_id(...).click()
but when I move the program to another computer, the button cannot be clicked, and error occur, I have to change the click() to something like
driver.find_element_by_id(...).send_keys(Keys.SPACE) or
element=driver.find_element_by_id(...).send_keys(Keys.SPACE)
driver.execute_script("arguments[0].click();", element)
or I have to try some other way around Does anyone have the same problem, and do you know what is the reason? because it is quite annoying that the code is fine in your computer but I am not feel safe to share it with others. Thank you
Upvotes: 0
Views: 229
Reputation: 31
I have had this issue with Internet Explorer while executing on different machines and the workaround(which is quite generic that it should work across browsers) that I used was to wait explicitly for the WebElement(button in your case) to be visible AND be clickable before I attempted a click event on it.
So, the code looked something like this:
WebDriverWait wait = new WebDriverWait(driver, 10);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath("Your path")));
wait.until(ExpectedConditions
.elementToBeClickable(By.xpath("The same path")));
} catch (Exception e) {
System.err.println("The error message to be displayed in console: "
+ e.getStackTrace());
} finally {
driver.findElement(By.xpath("The same path")).click();
}
The above code is in Java, but the premise will hold true in Python as well.
Upvotes: 1