Python/ Selenium is not sending tilde character (~

2019-06-11 06:25发布

问题:

I'm trying to use Python/ Selenium/ Webdriver to automatically fill an input field in my Chrome webpage. However, I am not able to use "send_keys" to fill out the tilde character.

Here is what I've tried so far:

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')

But the "~" tilde is not appearing on the field.

It is filled just as "charles18" instead of "charles~18"

Any help? Thanks!

回答1:

As per documentation you can call multiple time send_keys method.

Try this. 1. split url by ~ 2. send every fragmentation one by one. 3. only for ~ just send its unicode '\ue07E'

However this is not specify anywhere. but 7E is unicode for ~ special key mapping for selenium is here. Hope this help.

Java doc for selenium key is here