Check if element is clickable in Selenium Java

前端 未结 7 2007
南旧
南旧 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:10

    From the source code you will be able to view that, ExpectedConditions.elementToBeClickable(), it will judge the element visible and enabled, so you can use isEnabled() together with isDisplayed(). Following is the source code.

    public static ExpectedCondition<WebElement> elementToBeClickable(final WebElement element) {
    		return new ExpectedCondition() {
    			public WebElement apply(WebDriver driver) {
    				WebElement visibleElement = (WebElement) ExpectedConditions.visibilityOf(element).apply(driver);
    
    				try {
    					return visibleElement != null && visibleElement.isEnabled() ? visibleElement : null;
    				} catch (StaleElementReferenceException arg3) {
    					return null;
    				}
    			}
    
    			public String toString() {
    				return "element to be clickable: " + element;
    			}
    		};
    	}

    0 讨论(0)
提交回复
热议问题