简体   繁体   中英

Error while running selenium test case for a same code that ran last week

I am running the code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
import time

driver=webdriver.Chrome(executable_path="C:\driver\chromedriver_win32\chromedriver.exe")
driver.get("https://www.bobology.com/public/What-is-a-Mouse-Over-or-Mouse-Hover.cfm")
driver.maximize_window()
a=driver.title
print(f'The title of the page is {a}')
#driver.execute_script("window.scrollBy(0,100)","")
#path=driver.find_element_by_xpath("//*[@id='content']/div/div[3]/div/div/div/p[9]/strong/a")
#driver.execute_script("arguments[0].scrollIntoView();",path)
#time.sleep(5)
main=driver.find_element_by_xpath("//*[@id='mgtoppanel']/li[2]/a")
sub=driver.find_element_by_xpath("//*[@id='mgtoppanel']/li[2]/ul/li[1]/a")

action=ActionChains(driver)
action.move_to_element(main).move_to_element(sub).click().perform()
driver.close()

It was running fine till last week, and when I try to run the code today, I get the following error

C:\Python\Python39\python.exe C:/Users/Acer_Owner/PycharmProjects/sel1/scroll.py
Traceback (most recent call last):
  File "C:\Users\Acer_Owner\PycharmProjects\sel1\scroll.py", line 1, in <module>
    from selenium import webdriver
  File "C:\Python\Python39\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "C:\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 29, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "C:\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 27, in <module>
    from .remote_connection import RemoteConnection
  File "C:\Python\Python39\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 24, in <module>
    import urllib3
  File "C:\Python\Python39\lib\site-packages\urllib3\__init__.py", line 7, in <module>
    from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
  File "C:\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "C:\Python\Python39\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
  File "C:\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 199, in load_module
    mod = mod._resolve()
  File "C:\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "C:\Python\Python39\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
    __import__(name)
  File "C:\Python\Python39\lib\http\client.py", line 71, in <module>
    import email.parser
ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package

Process finished with exit code 1

PS- selenium is updated Requirement already satisfied: selenium in c:\\python\\python39\\lib\\site-packages (3.141.0) Requirement already satisfied: urllib3 in c:\\python\\python39\\lib\\site-packages (from selenium) (1.25.9)

I had a file named email.py.

Renaming it helped.

It is always suggested to not name the project, package and module same as the existing library packages/classes. The error was also coming in your case because of the email package already existing in in-built library.

Renaming the module other name will definitely work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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