2014-01-27 13 views
0

我是新來的自動化測試。我使用twitter作爲測試網站來學習硒。在TestNG上彈出並保存輸入文本

我想創建一個新的推文,併爲此我使用下面的場景。我可以打開「新推文」彈出窗口,但仍然無法在文本框中輸入文本。請幫忙。

前提條件:登錄到Twitter的

  1. 單擊按鈕(用於創建新的鳴叫)在屏幕的右上方。 彈出窗口打開
  2. 單擊彈出窗口上的文本框輸入文本。 光標獲取文本框中突出顯示和保存按鈕使
  3. 輸入一些文字
  4. 點擊保存按鈕

對我來說,它的工作,直到2點之後,它不會在文本

輸入文本

見下面我的代碼:

String popUpHandle = driver.getWindowHandle(); 

driver.switchTo().window(popUpHandle); 

driver.findElement(By.id("global-new-tweet-button")).click(); 

driver.findElement(By.xpath("(//button[@type='button'])[123]")).click(); 

driver.findElement(By.xpath("(//button[@type='button'])[123]")).sendKeys("test tweet"); 

driver.findElement(By.xpath("//button[@type='button'])[106]")).click(); 
+0

它會拋出異常嗎? –

回答

0

@ user3241182

我只是自己測試了一下。您不需要使用任何窗口處理。 代碼下面是提供的解決方案,效果很好。

WebDriver driver = new FirefoxDriver(); 
    driver.get("https://twitter.com/"); 
    WebElement username = driver.findElement(By.id("signin-email")); 
    username.clear(); 
    username.sendKeys("your_twitter_handle"); 
    WebElement pass = driver.findElement(By.id("signin-password")); 
    pass.clear(); 
    pass.sendKeys("your_twitter_passwd"); 
    WebElement signInButton = driver.findElement(By.xpath("/html/body/div/div[2]/div/div[2]/div[2]/div[2]/form/table/tbody/tr/td[2]/button")); 
    signInButton.click(); 
    WebElement tweetButton = driver.findElement(By.id("global-new-tweet-button")); 
    tweetButton.click(); 
    WebElement tweetBox = driver.findElement(By.id("tweet-box-global")); 
    tweetBox.clear(); 
    tweetBox.sendKeys("This is an automated tweet!"); 
    WebElement tweetSubmit = driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[2]/div[2]/form/div[2]/div[2]/button")); 
    tweetSubmit.click(); 
相關問題