1

I am trying to insert a value into the Google Search field. Here is the code in IPython:

    In [1]: from selenium import webdriver

    In [2]: driver=webdriver.Chrome("/ChromeDriver/chromedriver")

    In [3]: driver.get("https://www.google.com/")

    In [4]: i=driver.find_elements_by_id("lst-ib")[0]

    In [5]: i.click()

    In [6]: i.sendKeys("test")
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-6-dcc9ebf0e928> in <module>()
    ----> 1 i.sendKeys("test")

    AttributeError: 'WebElement' object has no attribute 'sendKeys'

    In [7]: i.setAttribute("value","test")
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-7-cf9217d1c7f8> in <module>()
    ----> 1 i.setAttribute("value","test")

    AttributeError: 'WebElement' object has no attribute 'setAttribute'

i is the Google Search input field, which I can't fill with values. Does anybody know how to insert values into this field?

1 Answer 1

1

sendKeys() is Java method. You need send_keys():

i.send_keys("test")

Also note that there is no such method as setAttribute() in Python. You might need to use

driver.execute_script('arguments[0].setAttribute("value", "test")', i)
Sign up to request clarification or add additional context in comments.

Comments

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.