Reputation: 155
I'm unable to locate the element using any of the locator techniques.
So far I've tried- By.linkText, By.cssSelector & By.xpath but to no avail. This is happening when I try to login using a different java class. However, if I write all my code in a single java class with the following selector (By createAccount = By.cssSelector("a.createAccount");) this error is not seen.
<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>
Would appreciate suggestions.
EDIT : Added the corresponding Java code
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);
}
}
Thanks
Upvotes: 1
Views: 3223
Reputation: 348
@user1502890, try this
By createAccount = By.linkText("Create Account");
OR
By createAccount = By.partialLinkText("Create Account");
If this do not solve the problem try to use WebDriverWait while finding the elements.
Upvotes: 2