Issue
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))
Solution
Failed to pass driver correctly.
Updated my code by passing the driver . Its working fine now .
Answered By - S_G
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.