无法使用python单击输入字符串

时间:2017-12-03 07:39:04

标签: 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'  

任何人都可以帮我跟踪问题吗?

1 个答案:

答案 0 :(得分:0)

使用这个来查看是否发生错误

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