Note- Use javascript because if any textbox is disabled then in that case sendKeys() method will not work.
ex- <input id="txt2" class="posStat" type="text" disabled="disabled" maxlength="100">
Reference Code-
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Naukari{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get("http://www.naukri.com");
driver.findElement(By.partialLinkText("Post Resume")).click(); //click in post resume
WebElement user= driver.findElement(By.xpath("//input[@id='txt2']")); //Enter your Email ID* : , textbox
System.out.println(user.isEnabled()); //this will give false
//user.sendKeys("hello1"); //if u will try this, this will fail
((JavascriptExecutor)driver).executeScript("document.getElementById('txt2').value='sanjay'"); //this is how , to use javascript to send value
WebElement pass = driver.findElement(By.xpath("//input[@id='password']")); //this field is not disabled so for this sendKeys() method can be used.
System.out.println(pass.isEnabled()); //this will print true
pass.sendKeys("hello"); //this will send the value in, Create a Password for your account* :
}
}
ex- <input id="txt2" class="posStat" type="text" disabled="disabled" maxlength="100">
Reference Code-
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Naukari{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get("http://www.naukri.com");
driver.findElement(By.partialLinkText("Post Resume")).click(); //click in post resume
WebElement user= driver.findElement(By.xpath("//input[@id='txt2']")); //Enter your Email ID* : , textbox
System.out.println(user.isEnabled()); //this will give false
//user.sendKeys("hello1"); //if u will try this, this will fail
((JavascriptExecutor)driver).executeScript("document.getElementById('txt2').value='sanjay'"); //this is how , to use javascript to send value
WebElement pass = driver.findElement(By.xpath("//input[@id='password']")); //this field is not disabled so for this sendKeys() method can be used.
System.out.println(pass.isEnabled()); //this will print true
pass.sendKeys("hello"); //this will send the value in, Create a Password for your account* :
}
}
Really good post & helpful .. (Y)
ReplyDelete