Troubleshooting problem with input fields in Protractor due to sendKeys malfunction

My current task involves automating end-to-end tests using Protractor on an Angular application. However, I've encountered an issue with sending keys to input fields. The sendKeys function consistently misses a few characters each time it is used, so I came up with a workaround:

static sendKeys(value, element){
    value.split('').forEach((c) => element.sendKeys(c));
}

While this workaround effectively solves the issue, it unfortunately takes more than three times longer than the original sendKeys function.

Despite the slower execution, my tests are still functioning properly. Recently, the app introduced new fields with scripts attached to them. One of these fields is a datepicker input, where you can either select a date from the date picker or manually type it in. When entering today's date as '09022018', the slashes automatically appear in the correct positions (e.g., '09/02/2018'). If an incorrect date is entered, the field is then cleared.

The main problem arises when it seems that both my custom implementation of sendKeys and the original one lose focus after each key press. This prevents me from entering a valid date in the input field as it gets cleared after each simulated key press.

While I could potentially use browser.executeScript to resolve this issue, doing so would prevent me from testing the functionality of adding automatic slashes. Additionally, since the datepicker stays open and refreshes after each key press, being able to pick a date from it at any moment is also a feature that I need to test.

Thank you in advance for any assistance.

Answer №1

Utilize the executeScript method to manipulate the background date setting, followed by using sendKeys to insert a space or Tab at the end to prompt the Keyboard event responsible for checking and formatting the input with slashes.

function setDate(inputDate) {

    var script  = 'arguments[0].value=arguments[1]';
    // locating the input field for the date
    var dateField = element(by.xxx(yyy));

    browser.executeScript(script, dateField, inputDate);

    dateField.sendKeys(" ");

    // alternatively, try sending a Tab key
    dateField.sendKeys(protractor.Key.TAB);
}

setDate('09022018');

You may apply this technique to resolve issues in other fields as well, but it may require an additional 3 attempts.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the solution for resolving the error "chromedriver.exe executable must be added to the PATH" in GitHub Actions?

My test setup involves a simple script like this: When I run it locally: from django.contrib.staticfiles.testing import StaticLiveServerTestCase from selenium.webdriver.chrome.webdriver import WebDriver from selenium import webdriver class TestKundeSeite ...

How can Selenium interact with various shadow DOM elements within a dropdown menu?

I am attempting to interact with a dropdown menu in order to track activity on the page when clicking on one of its items. Here is an overview of my HTML structure: <slot> #shadowroot <myoption-cmp> #shadowroot <some anchor te ...

Retrieve browser logs and cause the TestNG test to fail if any severe logs are found in the browser console

I'm currently in the process of developing an automated framework using Selenium, TestNG, and Java. One feature I am working on is checking browser logs during test execution. If any SEVERE logs are detected, I want the corresponding test to be marked ...

Is it possible to use Webdriver (ChromeDriver) alongside Play framework?

Currently, I am facing an issue with ChromeDriver within the Play! framework. In my UnitTest, I have instantiated ChromeDriver to make a get request to my Dyndns URL. However, upon initiating the test, Chrome opens, makes the request, but unfortunately, th ...

Using Selenium to Implement Accept Policy Targeting

I am attempting to locate and click on a button from dekudeals using selenium. Specifically, I am trying to target the accept button within the site's policy window. The button that needs to be clicked can be found here. I have made several attempt ...

The website's reaction to the request for URLs was not what was anticipated

I'm trying to load a website and scrape all of the links, which is usually simple but I encountered an unusual response today: links = WebDriverWait(web, 20).until(EC.presence_of_all_elements_located((By.XPATH,'//a[@href]'))) print("Thi ...

Having difficulty retrieving the alert text with selenium webdriver

I am currently facing an issue with verifying and dismissing alert text in my code. Despite following the steps to verify the alert text, I encountered failure. WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions. ...

How to properly set up geckodriver for selenium-webdriver on Ubuntu 18.04?

Currently, I am working on a specific web scraping task using Selenium in Node.js. The code is running smoothly on my local Mac machine. However, when I attempt to execute the same code on a demo Google Compute virtual machine instance, I am facing challen ...

The latest version of chromedriver.exe for .Net, version 2.36, is not functioning properly with chrome 64

Last year everything was working fine, but recently when I tried to run the program, I encountered an annoying error message: "chromedriver.exe has stopped working". The exception thrown was: OpenQA.Selenium.WebDriverException: 'An exception with a nu ...

Enhance tables that are created on the fly

After specifying conditions and clicking the inquiry button, a total of 76 rows are dynamically generated in the table. When you scroll on the screen, 76 new data entries corresponding to what is visible on the screen will load. Keep in mind that there are ...

Python's web scraping with Selenium

I have encountered an issue while trying to extract data from an HTML table. Although I was able to successfully count the rows, the problem arises when I attempt to print the data as it ends up repeating the same row multiple times. Can someone please h ...

Clicking on a hyperlink with Python Selenium, yet staying on the current page

Struggling to navigate a javascript page for web scraping using Selenium. The issue lies in clicking through the page's content. Instead of moving to another page, a click brings up the next set of reviews that I aim to scrape. The initial click work ...

Executing a single test with multiple browsers using Selenium RC and Java

How can I execute my Selenium RC test case with JUnit4 on various browsers? What configurations need to be set up in: ** public void setUp() throws Exception { selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://(some ...

Ways to deliberately make a test case fail for a specific data set and then proceed with running the same script in TestNG

Currently, I have a test script that needs to run for "n" amount of data using @DataProvider. The issue arises when I use the "Assert" method to fail the test case for one particular set of data; it halts the execution of the entire Test Script. I am loo ...

I am attempting to utilize Selenium to access a waiting list and activate the button, but I am struggling to locate the specific element

I've attempted to locate the Join waitlist button using find_element_by_class_name and link text, but both methods have resulted in a NoSuchElement Exception. My goal is to simply click the Join waitlist button for . Any help would be greatly apprecia ...

Tips for transforming sample vb script code into java code

I am looking to transform the following VB Script code into Java. The goal is to ensure that var2 is included in var1. var1=test123 var2=Test If Instring (Ucase(var1),Ucase(var2)) <> 0 Then print "pass" End IF ...

What is the best way to send key combinations to a Selenium ChromeDriver?

While using uirecorder to create mocha test cases for testing my web program, I encountered an issue with sending key combinations such as "Metakey + R". Despite being able to easily send single keys like '{DOWN}', figuring out how to send key co ...

Encountering a stale element reference error while attempting to automate Microsoft Login using Selenium in C#

My current project involves implementing a Selenium C# class to manage the Microsoft Login process on a specific webpage. Within this task, I have created two pagination classes that capture elements for the initial and subsequent stages of the login. Addi ...

Utilizing PulseAudio within a docker container for capturing system audio recordings

Currently, I'm attempting to configure a Docker container with Selenium to capture browser activity along with system audio using ffmpeg. As of now, I've successfully implemented video recording with Xvfb, but the audio component seems to pose mo ...

Look for a specific element on the page and choose the "Next" option if the element

In my dynamic table, I have various links and I need to search for a specific link. this.table.element(by.cssContainingText('a','1616050')); If the link is not found on the current page, I want to click on the 'Next 30 records&ap ...