针对上周运行的同一代码运行硒测试用例时出错

问题描述

我正在运行代码

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

直到上周运行良好,当我今天尝试运行代码时,出现以下错误

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-硒已更新 已满足要求:c:\ python \ python39 \ lib \ site-packages中的硒(3.141.0) 已经满足要求:c:\ python \ python39 \ lib \ site-packages中的urllib3(来自硒)(1.25.9)

解决方法

我有一个名为email.py的文件。

重命名有帮助。

,

始终建议不要将项目,程序包和模块的名称与现有库程序包/类的名称相同。对于您而言,由于内置库中已经存在电子邮件包,因此也会出现错误。

重命名模块绝对可以。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...