org.openqa.selenium.NoSuchElementException无法找到element:method“:”link text“,”selector“:”http://

问题描述 投票:0回答:1

我无法使用任何定位器技术找到该元素。

到目前为止,我已经尝试过By.linkText,By.cssSelector和By.xpath,但无济于事。当我尝试使用不同的java类登录时会发生这种情况。但是,如果我使用以下选择器在一个java类中编写所有代码(通过createAccount = By.cssSelector(“a.createAccount”);),则不会看到此错误。

<a class="createAccount" href="https://www.***.com/registration/" tabindex="9">
<span class="fontIconCreateAccount mdxFont" aria-hidden="true">
<span class="icon icon--pep">
<span class="icon__add-button"></span>
</span>
</span>
Create Account
</a>

会很感激的建议。

编辑:添加了相应的Java代码

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

public class LoginPage {
    private WebDriver driver;

    public LoginPage(WebDriver driver) {
        this.driver=driver;
    }

    By createAccount = By.linkText("https://***.com/registration/");

    //By createAccount = By.cssSelector("a.createAccount");
    //By createAccount = By.xpath(".//*[@id='signInBottomInformationContainer']/a");
    public WebElement createAccountLink(){
        return driver.findElement(createAccount);
    }
}

谢谢

java html selenium xpath pageobjects
1个回答
1
投票

@ user1502890,试试这个

By createAccount = By.linkText("Create Account");

要么

By createAccount = By.partialLinkText("Create Account");

如果这不能解决问题,请尝试在查找元素时使用WebDriverWait。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.