python - 在父类python selenium中导入方法
问题描述
我有一个非常基本的问题,但我正在学习 Python。我想在使用 Selenium 的子类中使用从父级导入的模块。但是我在传递 child 中的参数时遇到问题。错误仍然是“模块”对象不可调用(最后一行)。我的可重现示例:
#my_file.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
import urllib.request
class MyParent:
def __init__(self, URL):
self.URL = URL
# Browser options
self.options = Options()
self.options.headless = False # Set True for Headless mode
self.driver = webdriver.Chrome(options=self.options)
self.delay = 3
self.driver.get(self.URL)
self.WebDriverWait = WebDriverWait(self.driver, self.delay)
self.EC = EC()
from my_file import MyParent as MyParent
class myChild(MyParent):
def __init__(self):
super().__init__("http://www.python.org")
def my_function(self):
elem = self.driver.find_element_by_name("q") #Here is working
wait = self.WebDriverWait
wait.until(self.EC.element_to_be_clickable((By.ID, "id-search-field"))) #!!!!THE ERROR
c = myChild()
c.my_function()
TypeError Traceback (most recent call last)
<ipython-input-2-a9a7698ab26a> in <module>
----> 1 c = myChild()
2 c.my_function()
<ipython-input-1-12db5db612ff> in __init__(self)
3 class myChild(MyParent):
4 def __init__(self):
----> 5 super().__init__("http://www.python.org")
6
7 def my_function(self):
~/Desktop/0.3/my_file.py in __init__(self, URL)
22 self.driver.get(self.URL)
23 self.WebDriverWait = WebDriverWait(self.driver, self.delay)
---> 24 self.EC = EC()
TypeError: 'module' object is not callable
解决方案
推荐阅读
- c# - 有没有办法将 IAsyncEnumerable 转换为 Stream?
- javascript - 如何在另一个 div 中的标签输入上显示多选下拉值?
- python - 通过 google play api 发布新版本返回 500 内部错误
- c# - c# 转义 " 字符
- java - 无法查找主机 Cluster0-XXXXX.mongodb.net 的 TXT 记录
- javascript - HTML5 视频 - onclick 播放到全屏
- python - 如何根据python中其他列的计算将值附加到新列?
- algorithm - 递归调用实际上如何在合并排序中工作?
- python - 在 python 中,如何在 Windows 中获取当前用户 SID?
- flutter - 如何使用 Flutter 更改 TextFormField 中边框线的颜色