@eldgammel

Selenium — тесты — почему не находит локатор?

Цель воспроизвести пять кликов, 4 клика работают, а вот пятый никак... Selenium не может найти локатор переменной test. Все предыдущее работает корректно.
Интересный момент в том, что когда удаляю предыдущие команды по локаторам (предыдущие 4 клика) и оставляю только один пятый
WebElement test = (new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class=\"nav__categories-header\"]//a"))));
            test.click();

то все работает, но весь код целиком не работает
Помогите, пожалуйста. За ранее спасибо

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("vasyaPupkin87@gmail.com");

            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);
        }
    }
}
  • Вопрос задан
  • 361 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы