简体   繁体   English

获取驱动程序的硒问题

[英]Selenium issue from getting the driver

This is the code I have but when I run it这是我拥有的代码,但是当我运行它时


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()

With the error:随着错误:

> 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

I run Python 3.8.5 not sure what I am doing wrong because I copied it word from word.我运行 Python 3.8.5 不知道我做错了什么,因为我从单词中复制了它。 Unless its a permission issue除非是许可问题

Well that's a simple one, you should use from selenium.webdriver.common.keys import Keys , the other way is invalid syntax.嗯,这很简单,你应该使用from selenium.webdriver.common.keys import Keys ,另一种方式是无效的语法。

This will import Keys which allows you to send special keys such as ENTER and CONTROL through selenium.这将导入Keys ,它允许您通过 selenium 发送特殊键,例如ENTERCONTROL You should always read what the error says, this time it said invalid syntax so you should check that.您应该始终阅读错误内容,这次它说无效语法,因此您应该检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM