我正在学习Selenium Webdriver并尝试编写一个简单的测试脚本.
目的是获取Gmail页面About Google上的链接,以便练习CSS定位器.
这是代码:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearch {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
WebElement aboutGoogle = driver.findElement(By.cssSelector("a:contains('About Google')"));
driver.close();
driver.quit();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下提到的例外:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector a:contains('About Google') is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: An invalid or illegal selector was specified
Command …Run Code Online (Sandbox Code Playgroud)