2

I am using Python to write a Selenium test script and I have not been able to use it to enter data for a text area. Entering data into this area appears to trigger a JavaScript function that caches the data for later submission to the server.

When I run the test Selenium successfully enters the value into the text area but upon saving it the value disappears and my system throws a validation error.

I am using IE 11 (the app is only partially functional in Firefox or Chrome).

Here is the Python code for updating the text area.

driver.get_element_by_id('product_description').send_keys('This is a product')

I am now trying to figure out how to get the page to trigger the JavaScript code so that the data is properly configured for submission to the server. I have tried several different methods to do this:

driver.get_element_by_id('product_description').clear()
driver.get_element_by_id('product_description').click()
driver.get_element_by_id('product_description').send_keys('This is a product')
driver.get_element_by_id('product_description').send_keys(Keys.TAB)

Are there other ways to enter data into this text area?

1

It rather sounds like your first port of call should be talking to your development team to find out exactly what processes are affecting the text entry.

There's definitely something moer than you know if those steps aren't providing results.

1

I've figured out how to deal with this issue.

I used the Visual Event tool to determine that edits to data in the text box triggered the JQuery change event.

Next, I learned a bit of JQuery so that I could use it to set the field value and fire the change event.

Finally, I replaced my original code with the snippet below.

driver.execute_script("$('.product_description').val('This is a product'); $('.product_description').change();")

This approach appears to work consistently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.