Python/ Selenium is not filling the tilde (~)

Asked

Viewed 125 times

0

I’m trying to use Python / Selenium / Webdriver to automatically fill in an entry field on my Chrome page. However, I am unable to use the "send_keys" command to fill the til character (~).

Here is my code:

import os
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

browser = webdriver.Chrome(executable_path=r"chromedriver.exe")

browser.get("https://mywebpageaddress")

browser.find_element_by_id("username").send_keys('charles~18')

The page is filled in as "charles18" instead of "Charles~18".

Note: Manually you can write "Charles~18" in this field via the browser.

Anyone know how to handle it? Thank you!

1 answer

0

It may be because send_keys sends keys through a layer before the system keyboard driver. As your keyboard has the Brazilian layout, the "~" is a silent key.

Try simply sending the "~" twice, exactly as if you were typing:

browser.find_element_by_id("username").send_keys('charles~~18')

(of course, if so, the problem will be serious if the mesmocode has to run in the cloud, for example on the server or in a Travis instance)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.