I'm new to Automation and I'm trying to test this site: https://magento.softwaretestingboard.com/
and on this page
driver.get("https://magento.softwaretestingboard.com/men/tops-men/jackets-men.html");
I want to use the "Jackets" text on the upper left to validate that the site has loaded to the appropriate page.
However, I get the NO SUCH ELEMENT EXCEPTION after using By.LinkText. Here's what I did to locate the element:
WebElement jackets = driver.findElement(By.linkText("Jackets"));
Boolean jacketStatus = jackets.isDisplayed();
"link text" implies it only looks for links, e.g. <a>
elements. The element you're looking for is a <span>
, which is not a link.
<h1 class="page-title" id="page-title-heading" aria-labelledby="page-title-heading toolbar-amount">
<span class="base" data-ui-id="page-title-wrapper">Jackets</span>
</h1>
I don't know Selenium, but if I look at this documentation page, I'd suggest checking for By.id("page-title-heading")
. HTML IDs should be unique on a single page, unlike link texts (note that the breadcrumb also contains a "Jackets" item).