如何使用webdriver的硒(硒2)用Java来输入文本框? [英] How to type in textbox using Selenium WebDriver (Selenium 2) with Java?

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

问题描述


我使用的硒2
但运行以下code后,我就能够在输入文本框。


 封装演员;
导入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驱动程序;  @之前
  公共无效设置()抛出异常{
  司机=新FirefoxDriver();
      driver.get(http://www.fb.com);
  }
  @测试
  公共无效测试()抛出异常{
      //selenium.type(\"id=gs_htif0,测试);
      的System.out.println(HI);
      // driver.findElement(By.cssSelector(#gb_1> span.gbts))点击()。
          selenium.waitForPageToLoad(3亿);          WebElement电子邮件= driver.findElement(By.id(电子邮件));          email.sendKeys(nshakuntalas@gmail.com);
          。driver.findElement(By.id(u_0_b))点击();
  }
  @后
  公共无效关闭()抛出异常{
      的System.out.println(你怎么样?);
  }}



解决方案

感谢朋友,我得到了一个答案。这是唯一可能的,因为你的帮助。大家给我一丝希望对解决这个问题。

下面是code:

包Facebook的;进口org.openqa.selenium.By;
进口org.openqa.selenium.WebDriver;
进口org.openqa.selenium.WebElement;
进口org.openqa.selenium.firefox.FirefoxDriver;
进口org.openqa.selenium.interactions.Actions;公共类Facebook的{
    公共静态无效的主要(字符串ARGS []){
        驱动程序的webdriver =新FirefoxDriver();
        driver.get(http://www.facebook.com);
        WebElement电子邮件= driver.findElement(By.id(电子邮件));
        操作建设者=新的动作(驱动器);
        操作seriesOfActions = builder.moveToElement(电子邮件)。单击()的SendKeys(电子邮件,gati.naveen@gmail.com);
        seriesOfActions.perform();
        WebElement通= driver.findElement(By.id(通行证));
        WebElement登录= driver.findElement(By.id(u_0_b));
        。操作seriesOfAction = builder.moveToElement(通)。点击()的SendKeys(通naveench),点击(登录)。
        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.
    }    
}

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

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