1

I am having the trouble with the send_keys

options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(executable_path= '/home/ec2-user/chromedriver', chrome_options=options)
base_url = "https://www.xxxxxxxx.com/"
driver.get(base_url)
driver.find_elements_by_xpath("//input[@id = 'homepage_search_box']")[0].send_keys("Pink's Hot Dogs")

the above code working perfectly in windows but when it comes to ubuntu it trowing an error like

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
  (Session info: headless chrome=67.0.3396.99)
  (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.14.47-56.37.amzn1.x86_64 x86_64)

HTML:

<form class="form-inline" onsubmit="simple_search(jQuery('#homepage_search_box').val());return false;">
    <div class="form-group col-md-8">
        <label class="sr-only" for="homepage_search_box">Company Name or Report #</label>
        <input name="homepage_search_box" id="homepage_search_box" class="form-control" placeholder="Company Name or Report #" type="text">
    </div>
    <div class="form-group col-md-4">
        <button type="submit" class="btn btn-default">Search</button>
    </div>
</form>

can any one help

driver.find_elements_by_xpath("//input[@id = 'homepage_search_box']")[0]

it is giving selenium object perfectly i am getting error at sending keys

0

3 Answers 3

1

To send character sequence to the search box you need to induce WebDriverwait for the desired element to be clickable and you can use either of the following solutions:

  • Code Block:

    # -*- coding: UTF-8 -*-
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_argument('disable-infobars')
    options.add_argument('--headless')
    driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://www.ripoffreport.com/")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.header-field#header-search-text"))).send_keys("Pink's Hot Dogs")
    # WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='header-field'][@id='header-search-text']"))).send_keys("Pink's Hot Dogs")
    print("Search Text Sent")
    
  • Console Output:

    Search Text Sent
    
Sign up to request clarification or add additional context in comments.

7 Comments

it is raising raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Checkout my updated answer and let me know the status
i am just added one line extra options.add_argument('headless') > WebDriverWait(driver, Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/ec2-usr/lib64/python3.6/site-packages/selenium/webdriver/s upport/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Checkout my updated answer and let me know the status
everything is working on windows,But in my server it is not working (aws fedora linux) send_keys unable to send the keys to search box
|
0

Cannot reproduce withought the actual url, but you can try a few things:

  • sleep a couple of seconds before sending keys (the page might not be loaded)
  • it might be worth trying Firefox/geckodriver instead of Chrome; I've had issues before with Chrome as well which do not seem to happen on Firefox.
  • Moreover, if you have an adblocker on Chrome when copying x_path etc it can sometimes change the page structure

Hope this helps!

1 Comment

yeah, can't seem to be able to access from the UK! sorry I couldn't be more useful :/
0

you can try with javaScript

        JavascriptExecutor executor = (JavascriptExecutor)driver;
        executor.executeScript("arguments[0].click();", webElement);
        executor.executeScript("arguments[0].setAttribute('value', '"+text which you want to enter+"');",webElement);

1 Comment

everything is working on windows,But in my server it is not working (aws fedora linux) send_keys unable to send the keys to search box

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.