0

I have an application that has worked correctly so far when logging in web form.

For several days there is an error that it cannot see the email item field: no such element: Unable to locate element: {"method": "css selector", "selector": "* [data-test =" email-input "]"}

I can't see any changes to this field name and can't find a solution to the problem.

My code snippet:

        ChromeOptions options = new ChromeOptions();
        options.addArguments("headless");
        WebDriver driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        String actualUrl = "https://www.zocdoc.com/signin?provider=1";
        driver.get(actualUrl);

        try {
            WebDriverWait waiter = new WebDriverWait(driver, 20);
            waiter.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("*[data-test=\"email-input\"]"))));
            waiter.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("*[data-test=\"email-input\"]")));
            log.info("element email-input found"); 
        } catch (NoSuchElementException e) {
            log.error("element email-input not found"); // this prints in log
        }
        driver.findElement(By.cssSelector("*[data-test=\"email-input\"]")).clear();
        driver.findElement(By.cssSelector("*[data-test=\"email-input\"]")).sendKeys("email@some.com");
        driver.findElement(By.cssSelector("*[data-test=\"password-input\"]")).sendKeys("password");
        driver.findElement(By.cssSelector("*[data-test=\"sign-in-form-submit\"]")).click();

do you know what is teh reason ? regards

edit: i also tried:

driver.findElement(By.xpath("/html/body/div/div/main/span/div/div/div/div/div/div/form/label[1]/div[2]/input")).sendKeys("email@some.com");

driver.findElement(By.cssSelector(".label:nth-child(1) > div.textbox__TextboxWrapper-brYYtk.jscnkz > input")).sendKeys("email@some.com");

driver.findElement(By.xpath("//*[@id="main"]/div/main/span/div/div/div/div/div/div/form/label[1]/div[2]/input")).sendKeys("email@some.com");

and it does not work too.

edit: it's resolved. the cause of the problem is the service protection by WAF:

Selenium scraper detected at loading first page

I got around this problem, added some parameters to my java bot and now incapsula cant detect this bot.

Pawel W
  • 101
  • 1
  • 1
  • 12

1 Answers1

1

The selector By.cssSelector("*[data-test=\"email-input\"]") is incorrect!

You are adding an * where you don't need it.

The * (put in the right place) means data-test with a value that includes "email-input".

The correct way to right this selector is:

By.cssSelector("[data-test*='email-input']")  

Or you can just remove the * as follows:

By.cssSelector("[data-test='email-input']")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • Unfortunately, these attempts: By.cssSelector ("[data-test = 'email-input']") By.cssSelector ("[data-test * = 'email-input']") By.cssSelector ("[data-test = \" email-input \ "]") still not working. As I wrote, my version used to work for a long time, until it suddenly stopped working. The problem is elsewhere, but I don't know what. I generated the login code for this form via selenium IDE chrome extension doing automatic code generation and it worked. Now this genertor generates the same code, but my code doesn't work anymore: / – Pawel W Jan 07 '21 at 15:22