0

Running a script that writes a block of code into a textarea on a website. The first four "lines" write correctly until var url = "https: at which point the cursor jumps to the upper left of the text area and then continues writing. Each time the / character is come across, the cursor returns to the upper left before continuing writing.

How can I prevent the cursor being affected.

I have tried \/, \\/, {/}, and similar ways to escape the slash.

self.driver.find_element_by_id('textarea').send_keys(
        '\nvar device = this\n\nvar url = "' + baseurl + '/' + firmwarename + '"\n\nvar conv = TR69.createConnection(device)\n\ntry {'+
   'var uuid = java.util.UUID.randomUUID().toString().replace("-","") \n'+

What it physically does:

myhiddenurl.comSG9C130016_prod-mycomponent-5260-8a.27.103-combined-squashfs.img.gsdf"
var conv = TR69.createConnection(device)
var device = this
var url = "http:

Notice that lines 3 and 4 should be 1 and 2. And that line 1 is the continuation of what is now line 4.

Here is sample code which shows the issue...

    firmwarename = "tchrisdemo-code-3-2-3.gsdf"
    self.driver.get("https://futureoftesting.us/os.html")
    self.driver.find_element_by_id('textarea').clear()
    baseurl = "http://myhiddendomain.com/"
    self.driver.find_element_by_id('textarea').send_keys(
        '\nvar device = this\n\nvar url = "' + baseurl + '/' + 
    firmwarename + '"\n\nvar conv = TR69.createConnection(device)\n\ntry {'+
   'var uuid = java.util.UUID.randomUUID().toString().replace("-","") \n'+
   'var dlRequest = new TR69.DownloadRequest() \n' )

Line 5 of the code is the problem...

I've tried a variety of changes akin to your comment. The .format one allowed one allowed one "/" through then jumped to the top of the textarea and continued writing on the next one.

    baseurl = r"http://myhiddendomain.com/"
    url = "{}/{}".format(baseurl,firmwarename)
    self.driver.find_element_by_id('textarea').send_keys(
        '\nvar device = this\n\nvar url = "' + baseurl + firmwarename + '"\n\nvar conv = TR69.createConnection(device)\n\ntry {'+
   'var uuid = java.util.UUID.randomUUID().toString().replace("-","") \n'+
   'var dlRequest = new TR69.DownloadRequest() \nThis is formatting: ' + url) 

which sadly generated this:

    var dlRequest = new TR69.DownloadRequest() 
    This is formatting: http:/myhiddendomain.com/
    var device = this    

Not sure I fully get this solution.
It appears after more searching that the "jumping cursor" is a known problem and that the "devs have to fix it"

TChrisev
  • 1
  • 2
  • 1
    It would help if you made a [mre]. Welcome to Stack Overflow btw! – wjandrea Oct 23 '19 at 23:33
  • Are you using Selenium? If so, please tag your question with it. – martineau Oct 24 '19 at 00:40
  • Added the code sample to show the issue and marked the question as Selenium related per wjandrea and marineau – TChrisev Oct 24 '19 at 16:52
  • If I replace the "/" with "/" or with %2f, the send_keys works as expected though the process that consumes this information does not like either... – TChrisev Oct 24 '19 at 17:27
  • @Marco D.G. I used your code directly and had the \n written to the textarea. the "/" in the url= definition still moved the cursor to the top left of the textarea and then continued writing... – TChrisev Oct 24 '19 at 19:52

1 Answers1

0

Backslash '\' is the escape character

So try \ / (space in between so it doesn't look like a V but you obv want without the space)