Issue
I'm getting this output in Sublime Text when trying to run this code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:/Users/josh.bailey/Documents/chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get ("https://vehicleenquiry.service.gov.uk/")
time.sleep(5)
search = driver.find_element_by_id("wizard_vehicle_enquiry_capture_vrn_vrn")
search.send_keys("*REDACTED*")
search.send_keys(Keys.RETURN)
time.sleep(5)
main = driver.find_element_by_class("reg-mark-sm")
print(main.text)
driver.quit()
This is pretty basic code, I'm just trying something out to make a business process a lot easier when inputting vehicle details into our database. The code isn't finished yet, but I'm only stuck because of this error printout:
Traceback (most recent call last):
File "C:\Users\josh.bailey\Documents\Test3.py", line 2, in <module>
from selenium import webdriver
File "C:\Users\josh.bailey\AppData\Roaming\Python\Python38\site-
packages\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "C:\Users\josh.bailey\AppData\Roaming\Python\Python38\site-
packages\selenium\webdriver\firefox\webdriver.py", line 27, in
<module>
from selenium.webdriver.remote.webdriver import WebDriver as
RemoteWebDriver
File "C:\Users\josh.bailey\AppData\Roaming\Python\Python38\site-
packages\selenium\webdriver\remote\webdriver.py", line 41, in
<module>
from .shadowroot import ShadowRoot
File "C:\Users\josh.bailey\AppData\Roaming\Python\Python38\site-
packages\selenium\webdriver\remote\shadowroot.py", line 21, in
<module>
from ..common.by import By
ModuleNotFoundError: No module named 'selenium.webdriver.common.by'
[Finished in 195ms]
There's definitely a by.py file in selenium\webdriver\common directory, just as there is a keys.py file. I've opened the by.py file and it appears to have all the content inside it should have. is there something I'm doing wrong? Any help would be appreciated. Thanks!
Solution
Hi Please correct the line it is "find_element_by_class_name"
main = driver.find_element_by_class("reg-mark-sm")
to
main = driver.find_element_by_class_name("reg-mark-sm")
here is the complete code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:/Users/josh.bailey/Documents/chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get ("https://vehicleenquiry.service.gov.uk/")
time.sleep(5)
search = driver.find_element_by_id("wizard_vehicle_enquiry_capture_vrn_vrn")
search.send_keys("*REDACTED*")
search.send_keys(Keys.RETURN)
time.sleep(5)
main = driver.find_element_by_class_name("reg-mark-sm")
print(main.text)
driver.quit()
Answered By - Learner
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.