2013-04-09 83 views
-1

我正在用selenium來模擬一個from。問題現在在resulat頁面selenium混淆了顯示文本的值:它顯示了我第一個文本中的「parisl」文本和「marseile」中的第二。我不明白有什麼問題selenium顯示頁面出錯

這是我的代碼

public class SeleniumExample { 
public static void main(String[] args) throws InterruptedException { 
    // The Firefox driver supports javascript 


    FirefoxProfile profile = new FirefoxProfile(); 
    profile.setEnableNativeEvents(true); 

    RemoteWebDriver driver = new FirefoxDriver(profile); 
    // WebDriver driver = new FirefoxDriver(); 

    // And now use this to visit Google 
    driver.get("http://www.voyages-sncf.com/"); 

    // Find the text input element by its name 
    driver.findElement(By.name("origin_city")).sendKeys("paris"); 

    driver.findElement(By.id("train-destination-city")).sendKeys("marseille"); 



     Thread.sleep(4000); 



    driver.findElement(By.id("train-book")).click();} 

} 

回答

0

這CocE的應該是工作。也許我有一個建議 - 但我必須猜測你不是英語:

爲了能夠使用我的硒腳本並擁有適當的關鍵事件,我不得不將英語鍵盤作爲我的默認系統佈局。當我的鍵盤設置爲捷克語(我的語言)時,一些重要事件無法正常工作。

因此,假如你使用法語的佈局,我建議你把它切換到英文作爲默認的鍵盤

+0

我認爲這是由網站的自動完成引起的問題 – asma 2013-04-09 15:13:15

0

當我打開頁面重定向我http://www.tgv-europe.com/不具有作爲您正在尋找這樣的輸入標籤以上。

也許網站有一些邏輯,根據地區重定向?

P.S與原始問題無關,但對您的建議是使用隱式等待而不是執行Thread.sleep。除非達到最大時間限制,否則隱式等待會一直等到您要查找的元素出現。

+0

不,因爲您不使用法國的谷歌.fr – asma 2013-04-09 15:13:54