Home > Enterprise >  Unable to sendKeys() into input text field
Unable to sendKeys() into input text field

Time:11-10

I intend to automate a simple form fill Junit test on the following website: https://newdesign.millionandup.com

The input textfield i am attempting to send keys to is identified with id=email and i have tried the following two methods: 1.

     WebElement passInput = driver3.findElements(By.className("sidebar__item-text")).get(0); // this xPath does the trick  
     wait.until(ExpectedConditions.visibilityOfElementLocated(emailLocator));
     passInput.click();
     passInput.sendKeys("emailID");
     Thread.sleep(3000); // only to see the result
WebElement em1 = driver3.findElement(emailLocator);
    JavascriptExecutor jse = (JavascriptExecutor)driver3;
    //driver3.findElement(emailLocator).sendKeys(emString);
    Thread.sleep(1000);
    jse.executeScript("arguments[0].click()", em1);
    jse.executeScript("arguments[0].value='[email protected]';", em1);
    if (em1.isSelected()) {
        System.out.println("email typed");
    } else {
        System.out.println("unable to send keys, element not interactable");
    }

To no avail in both cases, the textfield is still not interactable and i am unable to type the data into it.

EDIT: As suggested in the comments i have attempted a third way:

3.

WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='email']"))); 
     System.out.println("email input located");
     element.click();
     System.out.println("email input clicked");
     element.sendKeys(emString);

Element is actually located, but, as soon as the methods click() or sendKeys() are called, the execution stops after stating "element not interactable"

CodePudding user response:

The xpath - //input[@id='email'] is matching 9 elements in the DOM. Its important to find unique locators - Link to refer

And the pop-up for Register opens on mouse movement. After mouse movement, will be able to view and interact with the pop-up elements.

Used below xpath to send keys to the element Email Address and it worked for me.

//form[@id='frmLeadModal']//input[@id='email']

Try like below once, it might work for you too.

driver.get("https://newdesign.millionandup.com/#initial");

WebDriverWait wait = new WebDriverWait(driver, 30);

Actions actions = new Actions(driver);
actions.moveByOffset(100, 100).perform();
        
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//form[@id='frmLeadModal']//input[@id='email']"))).sendKeys("[email protected]");      
  • Related