E
E
eldgammel2021-04-19 15:49:36
Software testing
eldgammel, 2021-04-19 15:49:36

Selenium - tests - why does not find the locator?

The goal is to reproduce five clicks, 4 clicks work, but the fifth one doesn't... Selenium can't find the test variable locator. All of the above work correctly.
An interesting point is that when I delete the previous locator commands (previous 4 clicks) and leave only one fifth

WebElement test = (new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class=\"nav__categories-header\"]//a"))));
            test.click();

then everything works, but the entire code does not work
Please help. Thanks in advance

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import javax.swing.*;
import java.time.Duration;

public class Main {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver"); // путь к драйверу
        WebDriver driver = new ChromeDriver(); // запускаем Chrome
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); // настроили неявные ожидания

        // 10 секунд ожидания, чтобы все прогрузилось
        try {
            driver.get("https://turk.com/"); // запускаем сайт
            Thread.sleep(1000);
            WebElement signIn = (new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class=\"header__user-nav\"]//ul//li[3]//a"))));
            signIn.click();

            WebElement emaiField = driver.findElement(By.xpath("//div[@class=\"tab__content tab__content--current\"]//div[1]//div//input[@type=\"text\"]"));
            emaiField.click();
            emaiField.sendKeys("[email protected]");

            WebElement passwordField = driver.findElement(By.xpath("//div[@class=\"tab__content tab__content--current\"]//div[1]//div//input[@type=\"password\"]"));
            passwordField.click();
            passwordField.sendKeys("Test-me-test");

            WebElement enterToProfile = driver.findElement(By.xpath("//div[@class=\"modal__btn-wrap\"]//button"));
            enterToProfile.click();

            WebElement test = (new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class=\"nav__categories-header\"]//a"))));
            test.click();
            
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question