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 {

        driver.get("http://tenaciousd.com");
        ConstantsTest c = new ConstantsTest(driver);
        c.ticketButton().click();
        Thread.sleep(100000);

    }

这是它返回的错误:

java.lang.StackOverflowError
    at java.io.FileInputStream.<init>(FileInputStream.java:56)
    at java.net.SocketInputStream.<init>(SocketInputStream.java:61)
    at java.net.AbstractPlainSocketImpl.getInputStream(AbstractPlainSocketImpl.java:415)
    at java.net.Socket$2.run(Socket.java:875)
    at java.net.Socket$2.run(Socket.java:873)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.Socket.getInputStream(Socket.java:872)
    at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:85)
    at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:107)
    at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:184)
    at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:163)
    at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:132)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:186)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:151)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
    at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:316)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:295)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:133)
    at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:355)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:396)
    at org.openqa.selenium.By$ByCssSelector.findElement(By.java:406)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
    at domainEntities.ConstantsTest.ticketButton(ConstantsTest.java:23)
4

1 回答 1

5

您的 StackOverflow 问题来自您的ticketButton()方法。

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

您正在返回方法而不是元素。

public WebElement ticketButton() {
    WebElement ticketButton = driver.findElement(By.cssSelector("a.ticketButton"));
    return ticketButton;
}
于 2013-09-10T19:08:29.287 回答