2017-12-03 222 views
0

我有這個代碼的問題輸入字符串:無法點擊使用python

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 

#Getting local session of Chrome 
driver=webdriver.Chrome() 

#put here the adress of your page 
driver.get("https://www.google.co.in") 
#put here the content you have put in Notepad, ie the XPath 



elem=driver.find_elements_by_name('q')############### this is one of name 
elem.send_keys("google search through python") 



driver.close() 

輸出正顯示出ELEM列表爲空 爲什麼會出現空列表?

Traceback (most recent call last): 
    File "google.py", line 14, in <module> 
    elem.send_keys("google search through python") 
AttributeError: 'list' object has no attribute 'send_keys' 

任何人都可以幫助我跟蹤問題嗎?

+2

錯誤'elem'是** **列表名稱爲「Q」的所有元素。選擇你想要應用'send_keys'的人。例如,將您的代碼更改爲'elem [0] .send_keys(「bla」)'。 – Maroun

回答

0

使用這一個,看看是否出現

elem=driver.find_elements_by_name('q') 
for e in elem: 
    e.send_keys("google search through python") 
+0

嗨,埃米爾,感謝它工作正常。但我有問題在我的HTML頁面我沒有名稱我有ID,它不與ID工作。 –

+0

+0

無法找到輸入ID =「電子郵件文件上傳」 –