小编San*_*bra的帖子

CSS Locator with contains()使用Selenium WebDriver的InvalidSelectorException

我正在学习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)

java selenium css-selectors selenium-webdriver

6
推荐指数
2
解决办法
2万
查看次数