对于junit测试案例,我正在尝试打开一个浏览器,导航到我的网站,然后在字段中输入电子邮件。尽管我所有的命令都是正确的,但我不明白为什么它专门停止并显示第33行的错误。
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("testing@mailinator.com");
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();
}
}
CSS类查找元素的适当语法为:
driver.findElement(By.cssSelector("input._g-s-input"));
我假设" _g-s输入"是您的CSS类名称,如果不是这样,请用适当的CSS类名称替换。