VictoriaW
VictoriaW

Reputation: 86

pass string with HTML to send_keys in selenium

I have problems when I pass a string to send_keys that contains HTML. It all shifts. For example <tag>abc</tag>def becomes <tag>c</tagdef>. The text-field is described by:

<textarea maxlength="4000" id="some-id" rows="3" name="data[a][b]" class="a-form-normal" dir="auto" spellcheck="true"></textarea>

I don't really understand what happens and how I can avoid it. I normally pass my html-string with: description = '<tag>abc</tag>def' browser.find_element_by_id('some-id).send_keys(description) This results in the strange shifts, described above.

Instead I tried to paste the string instead:

os.system("echo %s| clip" % description.strip())
browser.find_element_by_id('some-id').send_keys(Keys.CONTROL,'v')

Then I get the error message: Syntax error: redirection unexpected

I am using Python 3.7 on a Raspberry Pi

Many thanks for your help

Upvotes: 0

Views: 98

Answers (1)

VictoriaW
VictoriaW

Reputation: 86

Got it solved by using a different way to copy to clipboard:

import pyperclip

description = '<tag>abc</tag>def'
pyperclip.copy(description)
browser.find_element_by_id('some-id').send_keys(Keys.CONTROL,'v')

But a way without clipboard is still missing ...

Upvotes: 2

Related Questions