I'm able to verify whether or not an element exists and whether or not it is displayed, but can't seem to find a way to see whether it is 'clickable' (Not talking about disabled).
Problem is that often when filling a webform, the element i want may be overlayed with a div while it loads. The div itself is rather hard to detect as it's id, name and even the css is flexible. Hence i'm trying to detect whether or not a input field can be 'clicked' or 'filled'. When the overlaying div is present, the field cannot be filled by a regular user (As the div would overlay the input field and not allow the user to fill it) but it can be filled by selenium. I want to prevent that and only allow selenium to fill it once the user can also fill it.
Solution 4: Using Actions class in Selenium The exception “Element is not clickable at point” might be thrown when the element is not under focus or the action is being performed on the incorrect WebElement. In such cases, you have to switch to the actual element and perform the click action.
Using web console of your browser inspect element to check if there is any attribute to disable the link using style, class etc. String temp = selenium. getAttribute(locator@attribute); Now you can verify the value of temp.
Move to Element: contextClick() method first performs mouseMove to the middle of the element location. This function performs the right click at the middle of the web element.
You can wait for the element to be clickable:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get("http://somedomain")
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "myDynamicElement"))
)
Or, you can follow the EAFP
principle and catch an exception being raised by click()
:
from selenium.common.exceptions import WebDriverException
try:
element.click()
except WebDriverException:
print "Element is not clickable"
You can use webElement.isEnabled()
and webElement.isDisplayed()
methods before performing any operation on the input field...
I hope this will solve you problem...
Else, you can also put a loop to check above 2 conditions and if those are true you can specify the input text and again you can find the same element and you can get the text of the webelement and compare that text with the text you entered. If those matches you can come out of the loop.
to click an (for selenium) unreachable element i alwas use:
public void clickElement(WebElement el) throws InterruptedException {
((JavascriptExecutor) driver).executeScript("arguments[0].click();", el);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With