How to Validate an International Number Text Box in Selenium

How to Validate an International Number Text Box in Selenium

3 July 2024 Stephan Petzl Leave a comment QA

When automating web applications using Selenium, you might encounter issues while trying to insert values into text fields, especially for international number text boxes. This guide provides some effective solutions to resolve this problem.

Understanding the Problem

In some cases, using standard methods like sendKeys() may not work as expected. This can be due to various reasons such as the text box being non-interactive or certain validations being enforced by the web application.

Solution 1: Use click() Before sendKeys()

One approach to ensure the text box is interactable is to use the click() method before using sendKeys(). Here’s an example:


Solution 2: Use JavaScript Executor

If the above method does not work, you can use JavaScript to input the text. This is particularly useful when dealing with complex web elements. Here’s how you can do it:

  WebElement wb = driver.findElement("phone"));
  JavascriptExecutor jse = (JavascriptExecutor)driver;
  jse.executeScript("arguments[0].value='(222)222-2222';", wb);

Additional Tips

For better performance and code readability, you might want to clear the input fields before inserting new values:

  WebElement objPh = driver.findElement("phone"));
  WebElement objSSN = driver.findElement("ssn"));

Ensuring Page Load and Element Visibility

Make sure the page is fully loaded and the text box is visible and enabled before interacting with it. You can use implicit waits to handle this:

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


By using these techniques, you should be able to successfully validate and input values into international number text boxes in Selenium. For more advanced strategies on handling different types of web elements and automation testing, visit our blog.

Enhance Your Testing with Repeato

If you are looking for a no-code solution to automate your iOS and Android app tests, consider using Repeato. Repeato leverages computer vision and AI to create, run, and maintain automated tests quickly and efficiently. It’s simple to set up and use, making it an excellent choice for quality assurance professionals who need to ensure their apps are functioning correctly without writing complex code.

Like this article? there’s more where that came from!