Handling disable Elements using JSE :
-----------------------------------
By using Selenium , we cannot handle disable elements.----> Go to JSE
if element is disabled, we can interact with that element using JSE
ex: if text box is disabled, We can enter data into textbox using JSE .
ex: if checkbox is disabled, we can click checkbox using JSE..
----------------------------
package Java Script executor Basics;
import org. openqa. selenium. By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class HandlingDisableElementsUsingJSE {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", ".\\Drivers\\chromedriver.exe");
// //open chrome browser
WebDriver driver = new ChromeDriver();
driver.get("file:///C:/brahma/Practise/qtp%20practise/web%20apps/ALL%20Web%20objects.html");
// click check box 'I have an aeroplane'
// driver.findElement(By.xpath("//input[@id='bikeid'][@name='bike'][@value='Car']")).click();
// not throwing any errror -- not clicking checkbox as it is disabled
// Note : it does not throw any error (or) exception if we click element which is disabled
// By using Selenium, we cannot click disabled element
/// JSE
// IF ele is disabled , we can handle those elements using JSE
// JS code: document.getElementsByName('bike')[2].click(); -- > not clicking checkox
// JSE: document.getElementsByName('bike')[2].checked = true; --- > working
// HW
//HW click 'Computer ' check box use id using JSE
// enter some data in 'ename ' text box -- disabled
// driver.findElement(By.name("myname")).sendKeys("Raju");// Excpetion
// " org.openqa.selenium.ElementNotInteractableException: element not interactable
// HW Enter data in 'ename' text box - disabled using JSE
// JSE: document.getElementsByName('myname')[0].value = "Raja";// ok
// document.getElementsByName('myname')[0].value = 'Raja';// ok
System.out.println("ends");
}
}