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"http://myhiddendomain.com/"
    self.driver.get("https://futureoftesting.us/os.html")
    self.driver.find_element_by_id('firstname').send_keys(baseurl)
    self.driver.find_element_by_id('textarea').clear()
    url = u''
    #url = "{}//{}".format(baseurl,firmwarename)
    self.driver.find_element_by_id('textarea').send_keys(
        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)

SG9C130016_prod-sagemcom-5260-8a.27.103-combined-squashfs.img.gsdf"

var conv = TR69.createConnection(device)

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

var url = "http:
Oct 26, 2019 in Selenium by tchrisev
• 130 points
1,222 views
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();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
answered Oct 29, 2019 by Abha
• 28,140 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,520 points
576 views
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,316 views
+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 28, 2018 in Selenium by nsv999
• 5,500 points
26,662 views
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 13, 2018 in Selenium by nsv999
• 5,500 points
5,869 views
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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,057 views
0 votes
1 answer
+5 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,790 points
3,477 views
0 votes
3 answers

How do I resolve the ElementNotInteractableException in Selenium WebDriver?

Hi Abish, ElementNotInteractableException occurs when an element is ...READ MORE

answered Aug 21, 2019 in Selenium by Abha
• 28,140 points

edited Aug 4, 2023 by Khan Sarfaraz 102,912 views
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 22, 2019 in Selenium by Abha
• 28,140 points
985 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP