小编ado*_*dom的帖子

java sendkeys错误键应该是一个字符串

我尝试使用用户名和密码传递给表单字段时收到错误sendKeys.下面是我的用户类,后面是我的测试类.有谁知道为什么应用程序没有传递字符串?

org.openqa.selenium.WebDriverException:未知错误:keys应该是一个字符串

public class User {
    public static String username;
    public static String password;


    public User() {
        this.username = "username";
        this.password = "password";
    }

    public String getUsername(){
        return username;
    }

    public String getPassword(){
        return password;
    }

}

@Test
public void starWebDriver()  {
    driver.get(domainURL.getURL());
    WebElement userInputBox, passInputBox;
    userInputBox = driver.findElement(By.xpath("//input[@name='email']"));
    passInputBox = driver.findElement(By.xpath("//input[@name='password']"));
    System.out.println("before sending keys");
    userInputBox.sendKeys(User.username);
}
Run Code Online (Sandbox Code Playgroud)

java selenium webdriver selenium-webdriver

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

页面没有被驱动

有人可以告诉我为什么我的页面没有使用下面的代码驱动?页面加载但驱动程序没有驱动单击ticketButton链接.我迷路了,可以帮忙.提前致谢.

package domainEntities;

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

public class ConstantsTest {
    WebDriver driver;
    public ConstantsTest(WebDriver driver){
        this.driver = driver;
    }

    public WebElement ticketButton() {
        WebElement ticketButton = driver.findElement(By.cssSelector("a.ticketButton"));
        return ticketButton();
    }
}


package test;

import domainEntities.ConstantsTest;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import static org.junit.Assert.fail;

public class TenaciousD{
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();
    WebDriver driver = new FirefoxDriver();

    @Test
    public void TenaciousD() throws InterruptedException { …
Run Code Online (Sandbox Code Playgroud)

java selenium

2
推荐指数
1
解决办法
76
查看次数

WebDriver无法找到 - 是[对象XrayWrapper [对象文本]

我试图使用以下路径通过xpath定位元素,但我收到以下错误.xpath有可能找到这个元素吗?或者这是驱动程序本身的问题?

我希望能够区分/ p [4]/text()[1]和/ p [4]/text()[2]中的值.

.//*[@id='content']/p[4]/text()[1]

org.openqa.selenium.InvalidSelectorException: The given selector .//*[@id='content']/p[4]/text()[1] is either invalid or does not result in a WebElement. The following error occurred:
Run Code Online (Sandbox Code Playgroud)

InvalidSelectorError:xpath表达式".//*[/ id ='content']/p [4]/text()[1]"的结果是:[object XrayWrapper [object Text]].它应该是一个元素.

这是一个例子的html.我试图用/ text()验证文本'(会话的额外问题)'.

<div class="ad_field">
<label for="survey_id">Survey</label>
(extra questions for session)
<br>

</div>
Run Code Online (Sandbox Code Playgroud)

java selenium xpath selenium-webdriver

2
推荐指数
1
解决办法
3132
查看次数

标签 统计

java ×3

selenium ×3

selenium-webdriver ×2

webdriver ×1

xpath ×1