Python Forum
Selenium sends enter instead of space
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium sends enter instead of space
#1
Hello, I am trying to send a simple query to google using selenium, but instead of typing spaces it presses the enter key. I even tried making it type letters one by one and it still does the same.
It works correctly in an Ubuntu VM I have in my laptop but when migrating to an Ubuntu server it sends enter when it should send space.
Below is my code (all the additional imports are for other things the code is going to do).

The code below should type "Hello my friend" into the textbox but instead it is typing "Hello" and pressing enter.

How can I fix this?

Thank you very much for your help

# -*- coding: utf-8 -*-
import datetime
import pandas as pd
import errno
import glob
import json
import logging
import os
import random
import re
import requests
import signal
import shlex
import subprocess
import urllib
from selenium.webdriver.common.keys import Keys
from   bs4 import BeautifulSoup
from   argparse import ArgumentParser
from   functools import wraps
from   subprocess import call
from   time import sleep
from   web2screenshot import make_screenshot
from   DataSource import SearchDB
from   selenium import webdriver
from   selenium.webdriver.chrome.options import Options
from   fake_useragent import UserAgent
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--window-size=1920,1080")
options.add_argument("--start-maximized")
browser = webdriver.Chrome(chrome_options=options)
browser.implicitly_wait(99)
browser.set_page_load_timeout(99)
browser.get("https://www.google.com")
testkey = "Hello My Friend"
input_element = browser.find_element_by_name("q")
for letter in testkey:
     input_element.send_keys(letter)
browser.quit
Reply
#2
I found a workaround for what I need to do: Copy the whole keyword to the clipboard (I do this using subprocess and xclip) and then having selenium press Shift + Insert in chrome.
Not an elegant solution, but it works.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,587 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Selenium to pick data from csv and enter into website Prince_Bhatia 1 6,298 Sep-08-2017, 10:58 AM
Last Post: hbknjr
  Selenium to pick data from excel and enter into backend Prince_Bhatia 0 2,967 Aug-30-2017, 10:32 AM
Last Post: Prince_Bhatia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020