2017-01-07 10 views
0

Googleのページを開くことはできますが、検索バーにはテキストを入力できません。私の実行は、Googleページを開いた後にのみ停止します。GoogleのページにSeleniumでデータを入力できません

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class FirePath { 

public static void main(String[] args) throws InterruptedException { 
// TODO Auto-generated method stub 
WebDriver Driver = new FirefoxDriver(); 
Driver.get("http://www.google.com"); 
//Driver.wait(50); 
Driver.findElement(By.xpath(".//*[@id='gs_htif0']']")).sendKeys("some text"); 
//Driver.findElement(By.cssSelector(".gb_P")).click(); 
//Driver.findElement(By.xpath("html/body/nav/div/a[1]")).click(); 
} 

} 
+1

idとして 'lst-ib'を使用します。 –

答えて

0

あなたが検索入力フィールドにテキストを入力したい場合は、次のコードを試してください:

Driver.findElement(By.xpath("//input[@id='lst-ib']")).sendKeys("some text"); 

または

Driver.findElement(By.id("lst-ib")).sendKeys("some text"); 
0

あなたが使用することができますを以下

コードですこれに続くコード。

WebDriver driver = new FirefoxDriver(); 
driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
driver.get("http://www.google.com/"); 

driver.findElement(By.id("lst-ib")).sendKeys("Some Text"); 
driver.findElement(By.id("_fZl")).click(); 
関連する問題