Reputation: 1
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. Unless its a permission issue
Upvotes: 0
Views: 36
Reputation: 1352
Well that's a simple one, you should use from selenium.webdriver.common.keys import Keys
, the other way is invalid syntax.
This will import Keys
which allows you to send special keys such as ENTER
and CONTROL
through selenium. You should always read what the error says, this time it said invalid syntax so you should check that.
Upvotes: 2