获取驱动程序导致的硒问题

时间:2020-09-26 05:24:12

标签: python selenium

这是我拥有的代码,但是当我运行它时


from import selenium.webdriver.common.keys

driver = webdriver.Chrome(executable_path="C:\Users\Egg\Desktop\Selenium Project\chromedriver.exe")

driver.get("http://www.google.com")

print(driver.title)

driver.close()

出现错误:

> Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\PyCharm 2020.2.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\PyCharm 2020.2.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Egg/PycharmProjects/SeleniumProject/MultiBrowser.py", line 2
    from import selenium.webdriver.common.keys
         ^
SyntaxError: invalid syntax

我运行Python 3.8.5不确定我在做什么错,因为我是逐字逐句地复制它的。除非有权限问题

1 个答案:

答案 0 :(得分:2)

这很简单,应该使用from selenium.webdriver.common.keys import Keys,另一种方法是无效的语法。

这将导入Keys,使您可以通过硒发送特殊密钥,例如ENTERCONTROL。您应该始终阅读错误的内容,这一次它显示的语法无效,因此您应该进行检查。