如何使用带有 Java 的 Selenium WebDriver (Selenium 2) 在文本框中输入? [英] How to type in textbox using Selenium WebDriver (Selenium 2) with Java?

查看:31
本文介绍了如何使用带有 Java 的 Selenium WebDriver (Selenium 2) 在文本框中输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Selenium 2.但是在运行以下代码后,我无法在文本框中输入.

<块引用>

 封装Actor;导入 org.openqa.*;导入 org.openqa.selenium.By;导入 org.openqa.selenium.WebDriver;导入 org.openqa.selenium.WebElement;导入 org.openqa.selenium.firefox.FirefoxDriver;导入 org.junit.*;导入 com.thoughtworks.selenium.*;//导入 org.junit.Before;公共类演员{公共硒硒;公共 WebDriver 驱动程序;@前public void setup() 抛出异常{驱动程序 = 新的 FirefoxDriver();driver.get("http://www.fb.com");}@测试public void Test() 抛出异常{//selenium.type("id=gs_htif0", "test");System.out.println("你好");//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();}@后public void Close() 抛出异常{System.out.println("你好吗?");}}

解决方案

谢谢朋友,我得到了答案.这只有在您的帮助下才有可能.你们都给了我解决这个问题的一线希望.

代码如下:

打包facebook;导入 org.openqa.selenium.By;导入 org.openqa.selenium.WebDriver;导入 org.openqa.selenium.WebElement;导入 org.openqa.selenium.firefox.FirefoxDriver;导入 org.openqa.selenium.interactions.Actions;公开课脸书{公共静态无效主(字符串参数[]){WebDriver 驱动程序 = 新的 FirefoxDriver();driver.get("http://www.facebook.com");WebElement email= driver.findElement(By.id("email"));动作生成器 = 新动作(驱动程序);动作 seriesOfActions = builder.moveToElement(email).click().sendKeys(email, "gati.naveen@gmail.com");seriesOfActions.perform();WebElement pass = driver.findElement(By.id("pass"));WebElement 登录 =driver.findElement(By.id("u_0_b"));动作 seriesOfAction = builder.moveToElement(pass).click().sendKeys(pass, "naveench").click(login);seriesOfAction.perform();司机.}}

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?");
  }

}

解决方案

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.
    }    
}

这篇关于如何使用带有 Java 的 Selenium WebDriver (Selenium 2) 在文本框中输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆