How to click on disabled web elements | Selenium Forum
M
Posted on 20/07/2016
Here is a sample code where I am not able to click disabled Web elements

WebElement box=driver.findElement(By.xpath("//*[@id='filter_data']/ul/li[3]/a"));

List<WebElement>AllOptions=box.findElements(By.xpath("//*[@id='filter_data']/ul/li[3]/ul/li/a"));

System.out.println(AllOptions.size());

for(int i=0;i<AllOptions.size();i++){
System.out.println(AllOptions.get(i).getText()+" "+ AllOptions.get(i).isDisplayed());

//AllOptions.get(i).click(); This is not working
}

However I can click manually using below code and working fine for me.

driver.findElement(By.xpath("//*[@id='filter_data']/ul/li[3]/a")).click();
driver.findElement(By.linkText("With Flight")).click();

but I wanted to automate this using above for loop and click on each list items present in the box.

Can you please take a look and guide me for this issue if possible?

I am using makemytrip web page for this test.

String myUrl="https://holidayz.makemytrip.com/holidays/india/inspireMeAction?isDestHoliday=true&selectedTabName=&depCity=Bangalore&fromSearchWidget=true&destAliasType=true&searchDep=&IKnowDep=Bangalore&dateType=All+Dates&dateSearched=All+Dates&dateFlexibleBy=&flexible=false&fromBreadCrump=true&budgetFilterValue=0&dest=&inspireSortValue=3";

driver.get(myUrl);

M
Replied on 21/07/2016

[quote:2gw27rw4]Here is a sample code where I am not able to click disabled Web elements
[/quote:2gw27rw4]

You need to use JavaScriptExecutor for this task, WebDriver is not able to click on elements which are disabled or invisible. So try something like

JavascriptExecutor js = (JavascriptExecutor) webDriver;
js.executeScript("document.querySelector(\"button[id=yourButton]\").click()");

http://stackoverflow.com/questions/18660917/click-on-disabled-element-using-actions-class-doesnt-work