2017-02-11 22 views
1

Google検索フィールドに値を挿入しようとしています。ここ はIPythonのコードです:Seleniumのテキストフィールドを編集します。

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は、私は値で埋めることができないGoogle検索の入力フィールドです。 誰でもこのフィールドに値を挿入する方法を知っていますか?

答えて

1

sendKeys()は、Javaの方法である。あなたはsend_keys()が必要です

i.send_keys("test") 

PythonsetAttribute()というような方法が存在しないことに注意してください。あなたが使用する必要があります

driver.execute_script('arguments[0].setAttribute("value", "test")', i) 
関連する問題