2016-08-02 16 views
0

gmailログインでエラーメッセージをキャプチャしようとしています。ユーザー名を入力して[次へ]ボタンをクリックしないと「メールを入力してください」というメッセージが表示されますが、エラーメッセージを返す - 引数が見つからない。 私のコードは次のとおりです。Selenium WebDriverがGmailログインのエラーメッセージを取得できません

import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.JavascriptExecutor; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.Assert; 

public class Msg 
{ 
    public static void main(String[] args) throws InterruptedException 
    { 
    WebDriver driver=new FirefoxDriver(); 
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
    driver.manage().window().maximize(); 
    driver.get("http://www.gmail.com/"); 
    driver.findElement(By.xpath(".//*[@id='next']")).click(); 
       Thread.sleep(2000); 
    WebElement ele=driver.findElement(By.xpath(".//*[@id='next']")); 
    String js="argument[0].style.height='auto';  argument[0].style.visibility='visible';"; 
    ((JavascriptExecutor)driver).executeScript(js,ele); 

    String actual=ele.getText(); 
    System.out.println(actual); 
    //String expected= "Please enter your email"; 
    Assert.assertEquals(actual, "Please enter your email"); 
    System.out.println("Pass"); 
    } 
} 
+0

このコードを試してみてください、あなたが取得しているエラーメッセージを共有していただけますか? – Harish

答えて

0

import java.util.concurrent.TimeUnit; 
    import org.openqa.selenium.By; 
    import org.openqa.selenium.JavascriptExecutor; 
    import org.openqa.selenium.WebDriver; 
    import org.openqa.selenium.WebElement; 
    import org.openqa.selenium.chrome.ChromeDriver; 
    import org.openqa.selenium.firefox.FirefoxDriver; 
    import org.testng.Assert; 

    public class Msg 
    { 
    public static void main(String[] args) throws InterruptedException 
    { 
     System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\LMS_Selenium\\chromedriver.exe"); 
    WebDriver driver=new ChromeDriver(); 
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
    driver.manage().window().maximize(); 
    driver.get("http://www.gmail.com/"); 
    driver.findElement(By.xpath(".//*[@id='next']")).click(); 
       Thread.sleep(2000); 
    WebElement ele=driver.findElement(By.xpath(".//*[@id='next']")); 
    WebElement error=driver.findElement(By.xpath(".//*[@class='error-msg']")); 
    String actual=error.getText(); 
    System.out.println(actual); 
    //String expected= "Please enter your email"; 
    Assert.assertEquals(actual, "Please enter your email."); 
    System.out.println("Pass"); 
    } 
    } 
関連する問題