You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux下Selenium Chrome Driver使用send_keys发送斜杠异常求助

解决Linux下Selenium send_keys输入URL字符顺序错乱问题
  • 核对Chrome与ChromeDriver版本匹配
    Linux环境下出现这类字符顺序异常,大概率是Chrome和ChromeDriver版本不兼容导致的。先执行google-chrome --version查看浏览器版本,下载完全对应的ChromeDriver替换现有文件,替换后记得执行chmod +x chromedriver赋予执行权限。

  • 禁用Chrome自动填充相关功能
    浏览器的自动填充或预测服务可能干扰输入逻辑,初始化Chrome时添加以下启动参数:

    from selenium.webdriver.chrome.options import Options
    
    chrome_options = Options()
    chrome_options.add_argument("--disable-autofill")
    chrome_options.add_argument("--disable-form-autofill")
    chrome_options.add_argument("--disable-predictive-service")
    
    driver = webdriver.Chrome(options=chrome_options)
    
  • 改用JavaScript注入方式输入
    绕过Selenium的键盘模拟机制,直接通过JavaScript设置文本框的值,避免按键顺序问题:

    # l为定位到的目标文本框元素
    driver.execute_script("arguments[0].value = 'https://google.com';", l)
    
  • 检查系统键盘布局
    确认Linux系统的键盘布局为美式英文(或符合输入逻辑的布局),执行localectl status查看当前布局,若异常可切换为us布局。

内容的提问来源于stack exchange,提问作者sadaf2605

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 19:06:18