2017-04-22 58 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類名稱。