Home > front end >  Is there something wrong with the way I am implementing sendkeys?
Is there something wrong with the way I am implementing sendkeys?

Time:10-14

Why does sendkeys not work here?

The website I am practicing on is https://www.cineplex.com/

@Test 
    public void testLogin() {
        driver.manage().window().maximize();
        driver.navigate().to("https://www.cineplex.com/");
        driver.findElement(By.id("meta-nav-menu--account")).click();
        driver.findElement(By.id("login")).click(); // work up to here
        
        driver.findElement(By.xpath("//*[@id=\'txtEmailAddress\']")).sendKeys("radsfsad"); // username login
        driver.findElement(By.xpath("//*[@id=\"txtPassword\"]")).sendKeys("afdsa");// pass login
    
    }

The inspect code for entering email

CodePudding user response:

The syntax seems to be incorrect, you can try:

driver.findElement(By.id("txtEmailAddress")).sendKeys("radsfsad");
driver.findElement(By.id("txtEmailAddress")).sendKeys("afdsa");

OR

driver.findElement(By.xpath("//input[@id='txtEmailAddress']")).sendKeys("radsfsad"); // username login

driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("afdsa");// pass login

CodePudding user response:

You can use explicitwait

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(20));

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("txtEmailAddress"))).sendKeys("Youlrogin");

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("txtPassword"))).sendKeys("YourPassword")

I am unable to access the url so make sure there is no iframe, in case of iframe you have to first switch() to the frame and then use the above statement

  • Related