0

I try to write in the text field using selenium but an error has occurred"unexpected identifier " w any helpenter image description here

Dina
  • 1
  • 1

1 Answers1

0

I am not sure what selector you are using, but if it is the same input tag as visible in your snapshot then you can try the below code. [it is just a blind attempt].

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("firstname"))).sendKeys("whatever");

and in general, you can also use the below code.

driver.findElement(By.name("firstname")).sendKeys("Whatever");

I believe you can take help from this thread - Selenium Webdriver: Entering text into text field

Below is the full working code. for demonstration, I have only filled firstname and secondname. do like the ans if it helps.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

public class Testing {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 30);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();

        String myurl = "https://www.phptravels.net/register";

        driver.get(myurl);

        WebElement FirstName = wait.until(ExpectedConditions.visibilityOfElementLocated
                (By.xpath("//input[@name=\"firstname\"]")));
        FirstName.sendKeys("Dina");

        WebElement LastName = wait.until(ExpectedConditions.visibilityOfElementLocated
                (By.xpath("//input[@name=\"lastname\"]")));
        LastName.sendKeys("Hayden");

        System.out.println("Successfully Enter Value in the textbox.");
    }
}
Swaroop Humane
  • 1,770
  • 1
  • 7
  • 17
  • but I wanna use angular thus,this is not support the a angular – Dina Jul 21 '20 at 20:58
  • Please provide a URL so that I can check. What error you are getting if you execute the above code.? – Swaroop Humane Jul 21 '20 at 22:08
  • `driver.findElement(By.xpath("//input[@name=\"firstname\"]")).sendKeys("Whatever");` – Swaroop Humane Jul 21 '20 at 22:48
  • https://www.phptravels.net/register thanks in advance – Dina Jul 22 '20 at 22:01
  • I have edited my answer with full working code. The error which you are getting is because of you are working with angular before loading it. for more information please take help from the below link. https://stackoverflow.com/questions/18044519/what-is-the-cause-for-angular-is-not-defined – Swaroop Humane Jul 24 '20 at 21:24