how do I escape the in a textarea for Python3 7 with Selenium

+1 vote

I am attempting to write a set of commands into a textarea on a form page.  Several of the commands include the "/" character.  When I use send_keys to write the strings, they write fine until I reach the "/" then the cursor moves to the upper left of the textarea and continues writing which of course jumbles up the text I am writing.  I've tried using the "\" and "{}" and r'/' and u'/' and so far nothing has stopped the behavior.  I can find no reference that the character ought to do that nor any suggestions for stopping it.

I created a mochup of the page I want to write on and I still see the issue.

The selenium code is briefly:

    baseurl = u""
    url = u''
    #url = "{}//{}".format(baseurl,firmwarename)
        u'\nvar device = this\n\nvar url = "'+baseurl+firmwarename+'"\n\nvar conv = TR69.createConnection(device)\n\ntry {'+
   u'var uuid = java.util.UUID.randomUUID().toString().replace("-","") \n'+
   u'var dlRequest = new TR69.DownloadRequest() \n')

The output is: (notice the last line ought to be complete and the second line)


var conv = TR69.createConnection(device)

try {var uuid = java.util.UUID.randomUUID().toString().replace("-","")
var dlRequest = new TR69.DownloadRequest()
var device = this

var url = "http:
Oct 25, 2019 in Selenium by tchrisev
• 130 points
Seems like the website has set a shortcut for the "/" that takes the cursor to the first line (or some other position). And that's why whenever you send the "/" character, it moves the cursor elsewhere. I don't think there's an alternative code for this. There could be workarounds but for that, I need to see the website html and how it works.
The futureoftesting site in the get() is about 4 lines line.  Just enough to populate the form.  It doesn't have anything in it.  Now that site, I was able to make kinda work by sending the text in the wrong order, knowing that the / would move me back to the top of the textarea.  In the production system that I was actually trying to interact with, the / character is ignored sometimes and used to "go to top" sometimes.  I really don't understand what is going on here


The code worked successfully for me. Here's the screenshot:

The code works fine. One more possibility is that you might have keyboard shortcuts set for your browser. Check for browser keyboard shortcuts and see if the character "/" for any shortcut. If yes, then remove it.

1 answer to this question.

0 votes

@tchrisev, try using Robot class with following commands after your send_keys() method:

Robot robot = new Robot();
answered Oct 29, 2019 by Abha
• 28,000 points

Related Questions In Selenium

+1 vote
2 answers

How do I make selenium check gmails quota storage and then execute another task in a new tab depending on the value?

Hi, Xpath.gettext try this if this doesn't work ...READ MORE

answered Oct 20, 2020 in Selenium by Roshni
• 10,420 points
0 votes
0 answers

How do I keep a session alive for long Selenium scripts in automation?

I am automating a task with Selenium ...READ MORE

Dec 16, 2020 in Selenium by AYUSHI
• 120 points
+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,520 points
0 votes
1 answer

How do i change the location where my file gets downloaded in Selenium Webdriver and firefox driver?

There are a couple of errors there. ...READ MORE

answered Apr 12, 2018 in Selenium by nsv999
• 5,520 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,843 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
0 votes
3 answers

How do I resolve the ElementNotInteractableException in Selenium WebDriver?

ElementNotInteractableException ElementNotInteractableException is the W3C exception which is ...READ MORE

answered Dec 13, 2020 in Selenium by Gitika
• 65,870 points
0 votes
1 answer

How to create a test case with TestNG in Selenium?

Hey Deepak, to create a Test Case ...READ MORE

answered May 21, 2019 in Selenium by Abha
• 28,000 points