簡體   English   中英

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

[英]org.openqa.selenium.NoSuchElementException Unable to locate element:method“:”link text“,”selector“:”http://

我無法使用任何定位器技術來定位元素。

到目前為止,我已經嘗試過-By.linkText,By.cssSelector和By.xpath,但無濟於事。 當我嘗試使用其他java類登錄時,就會發生這種情況。 但是,如果我使用以下選擇器(通過createAccount = By.cssSelector(“ a.createAccount”);)將所有代碼寫入單個Java類中,則不會看到此錯誤。

<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);
    }
}

謝謝

@ user1502890,試試看

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

要么

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

如果這樣做不能解決問題,請在查找元素時嘗試使用WebDriverWait。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM