Naveen Chhaniwal Naveen Chhaniwal - 2 months ago 16
Java Question

How to type in textbox using Selenium WebDriver (Selenium 2) with Java?

enter image description here
I am using Selenium 2.
But after running following code, i could not able to type in textbox.


package Actor;
import org.openqa.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.junit.*;
import com.thoughtworks.selenium.*;
//import org.junit.Before;
public class Actor {
public Selenium selenium;
public WebDriver driver;

@Before
public void setup() throws Exception{
driver = new FirefoxDriver();
driver.get("http://www.fb.com");
}
@Test
public void Test() throws Exception{
//selenium.type("id=gs_htif0", "test");
System.out.println("hi");
// driver.findElement(By.cssSelector("#gb_1 > span.gbts")).click();
selenium.waitForPageToLoad("300000000");

WebElement email=driver.findElement(By.id("email"));

email.sendKeys("nshakuntalas@gmail.com");
driver.findElement(By.id("u_0_b")).click();
}
@After
public void Close() throws Exception{
System.out.println("how are you?");
}

}


Answer

Thanks Friend, i got an answer. This is only possible because of your help. you all give me a ray of hope towards resolving this problem.

Here is the code:

package facebook;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class Facebook {
    public static void main(String args[]){
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.facebook.com");
        WebElement email= driver.findElement(By.id("email"));
        Actions builder = new Actions(driver);
        Actions seriesOfActions = builder.moveToElement(email).click().sendKeys(email, "gati.naveen@gmail.com");
        seriesOfActions.perform();
        WebElement pass = driver.findElement(By.id("pass"));
        WebElement login =driver.findElement(By.id("u_0_b"));
        Actions seriesOfAction = builder.moveToElement(pass).click().sendKeys(pass, "naveench").click(login);
        seriesOfAction.perform();
        driver.
    }    
}
Comments