I am running an automated test in selenium/intelliJ/Java. The webdriver is supposed to click the drop down menu on the Amazon nav bar and then click one of the links within the drop down menu. It does both these things correctly, the drop down option leads to its link, however the selenium test itself fails, here is the error:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"link text","selector":"Full Shop Directory"}
and here is my code:
package com.testing.webdriver;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebElement;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public class MyFirstTest {
WebDriver driver = new ChromeDriver();
@BeforeClass
public static void setupWebdriver() {
WebDriverManager.chromedriver().setup();
}
private static final By SHOP_BY_DEPARTMENT = By.cssSelector("#nav-link-shopall");
private static final By SHOP_ALL = By.cssSelector("#nav-flyout-shopAll > div.nav-template.nav-flyout-content.nav-tpl-itemList > a");
@Test
public void startWebdriver() {
driver.navigate().to("https://www.amazon.co.uk/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
WebElement shopByDepartment = driver.findElement(SHOP_BY_DEPARTMENT);
shopByDepartment.click();
WebElement ShopAllNav = driver.findElement(By.linkText("Full Shop Directory"));
ShopAllNav.click();
Assert.assertTrue("matches current url",
driver.getCurrentUrl().matches("https://www.amazon.co.uk/gp/site-directory/ref=nav_shopall_fullstore"));
}
@After
public void breakdown() throws InterruptedException {
Thread.sleep(20000);
driver.close();
}
The test should be passing as it does what I'm telling it. I assume it's something to do with the link being in the drop down menu, as the error says, but I still don't know how I would rectify this. Any help would be appreciated, thanks.
Aucun commentaire:
Enregistrer un commentaire