2017-05-05 444 views
1

运行此selenium脚本时出现错误。请建议可以做些什么来解决这个问题: 脚本:ModuleNotFoundError:没有名为'selenium'的模块

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
import re 
import csv 
import time 
driver = webdriver.chrome("<webdriver path>") 

driver.get("https://www.google.com/") 
driver.find_element_by_xpath('//*[@title="Search"]') 
send_keys('abc') 
driver.find_element_by_xpath('//*[@class="sbico _wtf _Qtf"]').click() 
time.sleep(5) 
driver.find_element_by_xpath('//[@id="rso"]/div[1]/div/div[1]/div/div/h3/a') 
print(var) 

错误: 回溯(最近通话最后一个): 文件 “C:/Users/admin/Desktop/test2.py”,2号线,在 来自selenium import webdriver ModuleNotFoundError:没有名为'selenium'的模块

我在Win 7 Professional 32位上安装了Python 3.6。我有Selenium Standalone Server版本3.4.0(link

+0

你安装了硒吗?像pip安装硒? – Exprator

+0

我有Selenium Standalone Server版本3.4.0(链接)。我也安装了ChromeDriver 2.29。我需要安装其他东西吗? –

+0

问题是硒文件没有被加载。去cmd并使用pip安装硒。 – Exprator

回答

3

尝试使用pip安装硒。使用以下命令。

python -m pip install -U selenium 
+0

谢谢,上面的问题是固定的,但我得到另一个错误:Traceback(最近调用最后): 文件“C:\ Users \ admin \ Desktop \ test2.py”,第7行,在 driver = webdriver。 chrome(“”) TypeError:'模块'对象不可调用 –

+0

您需要下载chrome驱动程序。检查以下链接:http://stackoverflow.com/questions/13724778/how-to-run-selenium-webdriver-test-cases-in-chrome – shahin

+0

你的命令与-m和-U为我工作。没有这些标志,它就不起作用。 – nobism

相关问题