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 25 in Selenium by tchrisev
• 130 points
105 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 by Abha
• 27,180 points

Related Questions In Selenium

+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,110 points
8,594 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 12, 2018 in Selenium by nsv999
• 5,110 points
1,800 views
0 votes
1 answer
0 votes
1 answer
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 409 views
+4 votes
6 answers
0 votes
1 answer

How do I resolve the ElementNotInteractableException in Selenium WebDriver?

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

answered Aug 21 in Selenium by Abha
• 27,180 points
702 views
0 votes
1 answer