【问题标题】:selenium_Login to gmail_Getting Error Exception in thread "main"selenium_Login to gmail_Getting Error Exception in thread "main"
【发布时间】:2017-05-05 18:42:24
【问题描述】:

我正在编写 selenium 程序以登录到 Gmail 帐户。我已通过源代码提供用户名,进一步的步骤是单击下一步按钮。

package com.core.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Gmaildemo {
    public static void main(String args[]) {
        System.setProperty("webdriver.chrome.driver", "D:\\REKHA\\SOFTWARES\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.gmail.com");
        driver.findElement(By.name("identifier")).sendKeys("rekha.sompalli@gmail.com");
        driver.findElement(By.className("RveJvd snByac")).click();
    }

}

出现以下错误。

线程“主”org.openqa.selenium.InvalidSelectorException 中的异常:无效选择器:不允许复合类名

出现以下错误。无法识别下一步按钮。

【问题讨论】:

    标签: selenium


    【解决方案1】:

    您试图单击<span> 元素,这是错误的。 span 没有点击功能。瞄准 ID 为 identifierNextdiv 元素。试试这个:driver.findElement(By.id("identifierNext")).click();

    Selenium 不允许在 By.className 中使用复合类名称。即使是这样,该特定名称 "RveJvd snByac" 在网页上也不是唯一的,并且可能会产生与预期不同的结果。

    【讨论】: