Check if element is clickable in Selenium Java

前端 未结 7 2042
南旧
南旧 2020-11-29 08:19

I\'m new to Selenium and need to check if element is clickable in Selenium Java, since element.click() passes both on

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 09:00

    There are instances when element.isDisplayed() && element.isEnabled() will return true but still element will not be clickable, because it is hidden/overlapped by some other element.

    In such case, Exception caught is:

    org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (781, 704). Other element would receive the click:

    Use this code instead:

    WebElement  element=driver.findElement(By.xpath"");  
    JavascriptExecutor ex=(JavascriptExecutor)driver;
    ex.executeScript("arguments[0].click()", element);
    

    It will work.

提交回复
热议问题