模块' webdriver_manager.driver'没有属性' find_element_by_id'
有人请帮我这个错误。当我没有pytest-bdd
添加。(使用pytest
框架)时,它正在工作。但是,当我创建.features
文件和步骤定义并访问此问题时,这次我面临此问题。在将测试结构与pytest-bdd
集成在一起时,该文件中没有任何更改。
尝试执行以下代码,面对“ Module'WebDriver_Manager.driver'没有属性'find_element_by_id'“错误。
代码:
from selenium.webdriver import ActionChains
from selenium.webdriver.support.select import Select
from Utilities import configReader
import logging
from Utilities.LogUtil import Logger
log = Logger(__name__, logging.INFO)
class BasePage:
def __init__(self, driver):
self.driver = driver
def click(self, locator):
if str(locator).endswith("_XPATH"):
self.driver.find_element_by_xpath(configReader.readConfig("locators", locator)).click()
elif str(locator).endswith("_CSS"):
self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator)).click()
elif str(locator).endswith("_ID"):
self.driver.find_element_by_id(configReader.readConfig("locators", locator)).click()
log.logger.info("Clicking on an element: " + str(locator))
def type(self, locator, value):
if str(locator).endswith("_XPATH"):
self.driver.find_element_by_xpath(configReader.readConfig("locators", locator)).send_keys(value)
elif str(locator).endswith("_CSS"):
self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator)).send_keys(value)
elif str(locator).endswith("_ID"):
self.driver.find_element_by_id(configReader.readConfig("locators", locator)).send_keys(value)
log.logger.info("Typing in an element: " + str(locator) + " value entered as : " + str(value))
def select(self, locator, value):
global dropdown
if str(locator).endswith("_XPATH"):
dropdown = self.driver.find_element_by_xpath(configReader.readConfig("locators", locator))
elif str(locator).endswith("_CSS"):
dropdown = self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator))
elif str(locator).endswith("_ID"):
dropdown = self.driver.find_element_by_id(configReader.readConfig("locators", locator))
select = Select(dropdown)
select.select_by_visible_text(value)
log.logger.info("Selecting from an element: " + str(locator) + " value selected as : " + str(value))
def moveTo(self, locator):
if str(locator).endswith("_XPATH"):
element = self.driver.find_element_by_xpath(configReader.readConfig("locators", locator))
elif str(locator).endswith("_CSS"):
element = self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator))
elif str(locator).endswith("_ID"):
element = self.driver.find_element_by_id(configReader.readConfig("locators", locator))
action = ActionChains(self.driver)
action.move_to_element(element).perform()
log.logger.info("Moving to an element: " + str(locator))
Someone please help me with this error. It is working when I run without pytest-bdd
additions.(working with pytest
framework). But when I create .features
file and step definition and accessing this, This time I'm facing this issue. Nothing changed in this file while integrating the test structure with pytest-bdd
.
Trying to execute below code and facing "module 'webdriver_manager.driver' has no attribute 'find_element_by_id'" error.
Code:
from selenium.webdriver import ActionChains
from selenium.webdriver.support.select import Select
from Utilities import configReader
import logging
from Utilities.LogUtil import Logger
log = Logger(__name__, logging.INFO)
class BasePage:
def __init__(self, driver):
self.driver = driver
def click(self, locator):
if str(locator).endswith("_XPATH"):
self.driver.find_element_by_xpath(configReader.readConfig("locators", locator)).click()
elif str(locator).endswith("_CSS"):
self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator)).click()
elif str(locator).endswith("_ID"):
self.driver.find_element_by_id(configReader.readConfig("locators", locator)).click()
log.logger.info("Clicking on an element: " + str(locator))
def type(self, locator, value):
if str(locator).endswith("_XPATH"):
self.driver.find_element_by_xpath(configReader.readConfig("locators", locator)).send_keys(value)
elif str(locator).endswith("_CSS"):
self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator)).send_keys(value)
elif str(locator).endswith("_ID"):
self.driver.find_element_by_id(configReader.readConfig("locators", locator)).send_keys(value)
log.logger.info("Typing in an element: " + str(locator) + " value entered as : " + str(value))
def select(self, locator, value):
global dropdown
if str(locator).endswith("_XPATH"):
dropdown = self.driver.find_element_by_xpath(configReader.readConfig("locators", locator))
elif str(locator).endswith("_CSS"):
dropdown = self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator))
elif str(locator).endswith("_ID"):
dropdown = self.driver.find_element_by_id(configReader.readConfig("locators", locator))
select = Select(dropdown)
select.select_by_visible_text(value)
log.logger.info("Selecting from an element: " + str(locator) + " value selected as : " + str(value))
def moveTo(self, locator):
if str(locator).endswith("_XPATH"):
element = self.driver.find_element_by_xpath(configReader.readConfig("locators", locator))
elif str(locator).endswith("_CSS"):
element = self.driver.find_element_by_css_selector(configReader.readConfig("locators", locator))
elif str(locator).endswith("_ID"):
element = self.driver.find_element_by_id(configReader.readConfig("locators", locator))
action = ActionChains(self.driver)
action.move_to_element(element).perform()
log.logger.info("Moving to an element: " + str(locator))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法正确通过驱动程序。
通过驱动程序通过驱动程序更新了我的代码。现在正常工作。
Failed to pass driver correctly.
Updated my code by passing the driver . Its working fine now .