运行Selenium脚本时遇到Firefox浏览器问题

时间:2016-08-11 05:18:00

标签: firefox selenium-webdriver selenium-firefoxdriver

功能

Firefox版本:45.0.2
Selenium:selenium-java-2.53.1(也用selenium-java-3.0.0-beta2试用)

代码

package Selenium_Practice;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Launch_Browser {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\Selenium_Practice\\EXEs\\geckodriver-v0.10.0-win64\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        driver.get("http://abcd.jsp");//just for reference

        driver.findElement(By.xpath("//input[@id='loginForm:user-name']")).sendKeys("admin");

        driver.findElement(By.xpath("//input[@id='loginForm:user-password']")).sendKeys("admin");

        driver.findElement(By.xpath("//input[@id='loginForm:submit']")).click();

        driver.close();

    }

}

错误

1470892418708 Marionette: Element is missing an accesible name -> id: loginForm:user-name, tagName: INPUT, className: 1470892418759 Marionette: Element does not have a correct accessibility role and may not be manipulated via the accessibility API -> id: loginForm:user-  password, tagName: INPUT, className: 

输入用户名,密码&点击“提交”按钮,登录表格即将刷新。请帮助解决问题。

另请告诉我如何在代码中加密密码,与QTP相同。

1 个答案:

答案 0 :(得分:0)

您最好使用以下内容:

    driver.findElement(By.xpath("//input[contains(@id,'user-name')]")).sendKeys("admin");

    driver.findElement(By.xpath("//input[contains(@id,'user-password')]")).sendKeys("admin");

    driver.findElement(By.xpath("//input[contains(@id,'submit')]")).click();

这是因为角色':'在XPath中具有特殊含义。

相关问题