0

我最近问了这个问题: Retrieving the value from a Selenium Webdriver WebElement field and pass it to a java variable

所以我实现了接受的答案,它允许我(或者我认为)将字符串的值传递给变量(articleName)。然后我想做的是将此变量传递给下一个类,以便超级用户可以通过字符串 articleName找到文章然后使用它(超级用户的仪表板中有很多文章)。

但是,我收到的消息是:java.lang.IllegalArgumentException:链接文本为空时找不到元素。在 org.openqa.selenium.By.linkText(By.java:63)

显然,我没有正确传递值。由于我是初学者,所以我可能会在这里超越自己,因此,如果有人可以解释我的错误的基本前提,我将不胜感激!下面的代码片段:

//类#1

public class EditorArticleCreator {

private static WebDriver driver;
public static String baseURL = TestEnv.getUrl();
public static String username = User.getUsernameEditor();
public static String password = User.getPasswordEditor();
static WebDriverWait wait;
static Date date = new Date();
public static String articleName;

public static String getArticleName(){
    return articleName;
}

//一些代码然后......

    WebElement articleTitleField =driver.findElement(By.cssSelector("#Article_Title"));
    articleTitleField.sendKeys("Editor_Feature_Article_" + date.toString());
    articleName = articleTitleField.getText();

//类#2

public class EditArticleSuperUser {

private static WebDriver driver;
public static String baseURL = TestEnv.getUrl();
public static String username = User.getUsernameSuperUser();
public static String password = User.getPasswordSuperUser();
static WebDriverWait wait;
public static String articleName = EditorArticleCreator.getArticleName();

//一些代码然后.....

    WebElement newarticle = driver.findElement(By.linkText(articleName));
    assertEquals("finds new article", articleName, newarticle.getText());
4

0 回答 0