Why the first code doesn't work while the second does?
First code:
import selenium
driver = selenium.webdriver.Firefox()
AttributeError: 'module' object has no attribute 'webdriver'
Second code:
from selenium import webdriver
driver = webdriver.Firefox()
Nested packages are not automatically loaded; not until you import selenium.webdriver
is it available as an attribute. Importing just selenium
is not enough.
Do this:
import selenium.webdriver
driver = selenium.webdriver.Firefox()
Sometimes the package itself will import a nested package in the __init__.py
package initializer; os
imports os.path
, so os.path
is immediately available even if you import just os
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With