Karl
Karl

Reputation: 149

Selenium Send Keys not working on Ubuntu with /

I'm running Selenium using Python 3.6.4 and Pytest 6.1.1 on Ubuntu 20.04, when I run the below command to send keys the "/" are removed from the output. In Windows they are not removed.

element.send_keys("sudo /bin/bash")

The end result is: sudo binbash

Any ideas how to solve this problem? I've tried escaping them and no luck.

Thanks for your time.

Upvotes: 0

Views: 446

Answers (1)

Karl
Karl

Reputation: 149

I tried sending it encoded and that didn't work.

What I came up with that worked was setting the value to the clip board and pasting it into the field using Ctrl + V.

from subprocess import PIPE, Popen        

p = Popen(["xsel", "-bi"], stdin=PIPE)
p.communicate(input=str.encode(text.strip()))
        
text_area = component.find_element_by_tag_name("textarea")
text_area.send_keys(Keys.CONTROL, "v")

Upvotes: 1

Related Questions