Bottom Page

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
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  webscrapping links and then enter those links to scrape data kirito85 2 179 Jun-13-2019, 02:23 AM
Last Post: kirito85
  Ajax and Selenium ankitjindalbti 3 371 May-31-2019, 03:40 PM
Last Post: ankitjindalbti
  Selenium Python migs2173 1 265 May-12-2019, 04:33 AM
Last Post: metulburr
  Error when trying to use Selenium ejected 1 352 Mar-26-2019, 04:53 AM
Last Post: ejected
  Web scraping (selenium (i think)) Larz60+ 10 890 Jan-27-2019, 02:57 AM
Last Post: Larz60+
  selenium timeout metulburr 8 603 Jan-14-2019, 03:21 PM
Last Post: metulburr
  selenium error : evilcode1 7 686 Nov-12-2018, 01:08 PM
Last Post: snippsat
  web scraping with selenium and bs4 Prince_Bhatia 2 749 Sep-18-2018, 10:59 AM
Last Post: Prince_Bhatia
  Looking for Selenium setup help ubotbuddy 3 456 Sep-15-2018, 05:56 PM
Last Post: ubotbuddy
  A problem with using selenium Truman 2 1,367 Aug-08-2018, 10:41 PM
Last Post: Truman

Forum Jump:


Users browsing this thread: 1 Guest(s)