【问题标题】:Error while running selenium test case for a same code that ran last week为上周运行的相同代码运行 selenium 测试用例时出错
【发布时间】:2020-09-10 05:28:10
【问题描述】:

我正在运行代码

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(来自 selenium)(1.25.9)

【问题讨论】:

  • 你有email.py的文件吗?
  • @DilipMeghwal 是的,我愿意
  • 将其名称更改为其他名称。

标签: python python-3.x selenium selenium-webdriver


【解决方案1】:

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

重命名有帮助。

【讨论】:

    【解决方案2】:

    始终建议不要将项目、包和模块命名为与现有库包/类相同的名称。由于内置库中已经存在电子邮件包,因此您的情况也出现了错误。

    将模块重命名为其他名称肯定会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 2016-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多