Reputation: 1
Trying to Run this code using POM but got error. selenium version= 4.8.3
Test Case File:
\`import time
from selenium import webdriver
from Functions import definedFunctions
from locators import Locators
from data import form
class New():
def __init__(self):
self.driver = None
def setup(self):
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://demoqa.com/")
def Text_box(self):
elm = definedFunctions(self.driver)
lc = Locators
data = form
elm.click_on_button(lc.var)
elm.click_on_button(lc.text_box)
elm.send_keys_by_xpaths(lc.full_name, data.NAME)
elm.send_keys_by_xpaths(lc.email, data.email)
elm.send_keys_by_xpaths(lc.curr_address, data.address_cur)
elm.send_keys_by_xpaths(lc.per_address, data.address_per)
elm.click_on_button(lc.submit_btn)
def Check_box(self):
elm = definedFunctions(self.driver)
lc = Locators
data = form
elm.click_on_button(lc.check_box)
elm.click_on_button(lc.plus_btn)
elm.click_on_button(lc.check1)
elm.click_on_button(lc.check2)
elm.click_on_button(lc.check3)
time.sleep(10)
\`obj = New()
obj.setup()
obj.Text_box()
obj.Check_box()\`\`
Function File
\`from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class definedFunctions:
def __init__(self, driver):
self.driver = driver
def click_on_button(self, xpath):
click = WebDriverWait(self.driver, 50).until(EC.visibility_of_element_located((By.XPATH, xpath)))
self.driver.execute_script("arguments[0].click();", click)
def send_keys_by_xpaths(self, xpath, key):
WebDriverWait(self.driver, 50).until(EC.presence_of_element_located((By.XPATH, xpath))).send_keys(key)`
Error occurred
" File "C:\Users\Lenovo\PycharmProjects\pythonProject1\TestCases.py", line 46, in <module> obj.Text_box() File "C:\Users\Lenovo\PycharmProjects\pythonProject1\TestCases.py", line 24, in Text_box elm.click_on_button(lc.var) File "C:\Users\Lenovo\PycharmProjects\pythonProject1\Functions.py", line 11, in click_on_button click = WebDriverWait(self.driver, 50).until(EC.visibility_of_element_located((By.XPATH, xpath))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\Desktop\New folder\Lib\site-packages\selenium\webdriver\support\wait.py", line 86, in until value = method(self._driver) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\Desktop\New folder\Lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 152, in _predicate return _element_if_visible(driver.find_element(*locator)) ^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'find_element'
Upvotes: 0
Views: 82
Reputation: 205
Check your "driver" parameter. Currently the error states, that a 'NoneType' object has no attribute 'find_element'.
_element_if_visible(driver.find_element(*locator)) ^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'find_element'
Looking at these lines of code we see the object is "driver".
driver.find_element(*locator)
So there is no valid driver provided.
With options provided it should work.
from selenium.webdriver.chrome.options import Options
options = Options()
options.page_load_strategy = 'normal'
driver = webdriver.Chrome(options=options)
source: https://www.selenium.dev/documentation/webdriver/drivers/options/
Upvotes: 0