Python Forum

Full Version: wait.until(EC.element_to_be_clickable) failed to click
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def FindElementById(Element):
    clickable = wait.until(EC.element_to_be_clickable((By.ID, Element)))
    clickable.click()
Chrome.FindElementById("user-id")
It is not able to perform the click function, and it seems like waiting for the element to present.
Thus, I wait until got TimeOutException.
Then I try this method
time.sleep(3)
Chrome.FindElementById("user-id")
And it able to perform the click after 3 seconds wait.

May I know why?
(Feb-21-2019, 04:11 PM)gahhon Wrote: [ -> ]def FindElementById(Element):
clickable = wait.until(EC.element_to_be_clickable((By.ID, Element)))
What exactly is your wait defined as? It should be WebDriverWait(driver, 3) but i cant see it.

Found this looking around
Quote:EC.element_to_be_clickable check if element is visible and enabled. In terms of visibility it doesn't cover scenario when element is behind other. Maybe your page use something like blockUI widget and click() occurs before the cover disappears. You can check if element is truly clickable by enriching EC.element_to_be_clickable((By.XPATH, x)) check with assertion that ensure element is not behind by other.

static bool IsElementClickable(this RemoteWebDriver driver, IWebElement element)
{
    return (bool)driver.ExecuteScript(@"
            (function(element){
                var rec = element.getBoundingClientRect();
                var elementAtPosition = document.elementFromPoint(rec.left+rec.width/2, rec.top+rec.height/2);
                return element == elementAtPosition || element.contains(elementAtPosition);
            })(arguments[0]);
    ", element);
}
(Feb-21-2019, 05:35 PM)metulburr Wrote: [ -> ]
(Feb-21-2019, 04:11 PM)gahhon Wrote: [ -> ]def FindElementById(Element):
clickable = wait.until(EC.element_to_be_clickable((By.ID, Element)))
What exactly is your wait defined as? It should be WebDriverWait(driver, 3) but i cant see it.

Found this looking around
Quote:EC.element_to_be_clickable check if element is visible and enabled. In terms of visibility it doesn't cover scenario when element is behind other. Maybe your page use something like blockUI widget and click() occurs before the cover disappears. You can check if element is truly clickable by enriching EC.element_to_be_clickable((By.XPATH, x)) check with assertion that ensure element is not behind by other.

static bool IsElementClickable(this RemoteWebDriver driver, IWebElement element)
{
    return (bool)driver.ExecuteScript(@"
            (function(element){
                var rec = element.getBoundingClientRect();
                var elementAtPosition = document.elementFromPoint(rec.left+rec.width/2, rec.top+rec.height/2);
                return element == elementAtPosition || element.contains(elementAtPosition);
            })(arguments[0]);
    ", element);
}


wait = WebDriverWait(instance, 30)
I just now try again it work again? @@
So sometime it work, sometime it not?
did you raise the number to 30? IF so then you just need more time before timeout.
https://selenium-python.readthedocs.io/a...pport.wait

Another option is the site you are crawling flagged your IP address, and reset today.
(Feb-22-2019, 05:47 PM)metulburr Wrote: [ -> ]did you raise the number to 30? IF so then you just need more time before timeout.
https://selenium-python.readthedocs.io/a...pport.wait

Another option is the site you are crawling flagged your IP address, and reset today.

Yes. The application is executing until timeout till can't allocate the element.