对于Junit测试用例,我正在尝试打开浏览器,导航到我的网站并在字段中输入电子邮件。虽然我的所有命令都是正确的,但我无法理解为什么它会特别停止并显示第33行的错误,即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("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();
}
}
答案 0 :(得分:1)
通过css类查找元素的适当语法是:
driver.findElement(By.cssSelector("input._g-s-input"));
我假设' _g-s-input'是你的css类名,如果不是,请用适当的css类名替换它。