2017-04-22 13 views
1

对于Junit测试用例,我试图打开浏览器,导航到我的网站并在字段中输入电子邮件。虽然我的所有的命令都是正确的,我无法理解为什么它明确停止,并显示错误线33即driver.findElement(By.cssSelector)在我的Junit测试用例driver.findElement(By.cssSelector)中未执行

package JUnitTesting; 

import static org.junit.Assert.*; 

import java.util.concurrent.TimeUnit; 

import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
//import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class BasicActions { 
    WebDriver driver; 
    String BaseUrl; 

    @Before 
    public void setUp() throws Exception { 
     //System.setProperty("webdriver.chrome.driver", "C:\\Automation\\chromedriver_win32\\chromedriver.exe"); 
     driver = new FirefoxDriver(); 
     BaseUrl = "https://www.flock.co/in/indexd/"; 
     driver.manage().window().maximize(); 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

    } 
    @Test 
    public void test() { 
     driver.get(BaseUrl); 
     System.out.println("opening the base url"); 
     driver.findElement(By.xpath("//div[@id='main-area']//input[@type='email']")).clear(); 
     driver.findElement(By.cssSelector("._g-s-input>input")).sendKeys("[email protected]"); 
     System.out.println("Entering a valid email id"); 
     driver.findElement(By.xpath("//div[@id='main-area']/div[2]/div[2]//button[@class ='_g-s-button']")).click(); 
     System.out.println("Redirecting to web.flock.co"); 
    } 

    @After 
    public void tearDown() throws Exception { 
     driver.quit(); 
    } 



} 
+0

什么是错误? – Grasshopper

+0

对于较新的Firefox> 47,您需要获得geckodriver。你可以在https://github.com/mozilla/geckodriver/releases下载驱动程序。把它放在路径中,我们通过设置系统属性System.setProperty(“webdriver.gecko.driver”,“geckodriver可执行文件的路径”);' –

+0

@adeealamsz我已经指定了路径。它仍然显示我这个错误 –

回答

1

适当的语法通过CSS类找到元素是:

driver.findElement(By.cssSelector("input._g-s-input")); 

我假设'_g-s-input'是您的css类名称,如果不是这样,请将其替换为适当的css类名称。