Skip to main content
 首页 » 编程设计

python之Selenium 未向输入字段发送波浪字符 (~)

2025年05月04日20freeliver54

我正在创建一个从 Excel 工作表获取 URL 的应用程序,但它在 URL 中有波浪号('~')。当我使用 selenium 将其复制到输入字段时,该字符不会自行复制。

我遇到了 this去年的帖子,但没有人能解决这个问题。所以希望有人会知道答案:)

提前致谢!

#Fill in Discription 
driver.find_element_by_xpath('//[@id="description"]').send_keys(Description) 
 

请您参考如下方法:

这是我们的 friend @Mithun Mandal 在另一篇文章中所说的内容的表示(它在 C# 中,考虑到它是 selenium,转换为 python 应该不难)。

string url = "www.test~dummy.com"; 
foreach (string x in url.Split('~')) 
{ 
    element.SendKeys(x); 
    element.SendKeys("\u223C"); 
} 
element.SendKeys(Keys.Backspace); //this is used to erase the wrong tilde typed at the end of the URL 

曾在这里工作。