尝试使用 POM 运行此代码但出现错误。硒版本= 4.8.3

问题描述 投票:0回答:1

尝试使用 POM 运行此代码但出现错误。硒版本= 4.8.3

测试用例文件:

\`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()\`\`

功能文件

\`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)`

发生错误

” 文件“C:\Users\Lenovo\PycharmProjects\pythonProject1\TestCases.py”,第 46 行,位于 obj.Text_box() 文件“C:\Users\Lenovo\PycharmProjects\pythonProject1\TestCases.py”,第 24 行,在 Text_box 中 elm.click_on_button(lc.var) 文件“C:\Users\Lenovo\PycharmProjects\pythonProject1\Functions.py”,第 11 行,在 click_on_button 中 单击 = WebDriverWait(self.driver, 50).until(EC.visibility_of_element_ located((By.XPATH, xpath))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件“C:\Users\Lenovo\Desktop\Newfolder\Lib\site-packages\selenium\webdriver\support\wait.py”,第 86 行,直到 值=方法(self._driver) ^^^^^^^^^^^^^^^^^^^^^^ 文件“C:\Users\Lenovo\Desktop\Newfolder\Lib\site-packages\selenium\webdriver\support xpected_conditions.py”,第 152 行,在 _predicate 中 返回_element_if_visible(driver.find_element(*locator)) ^^^^^^^^^^^^^^^^^^^^ AttributeError:“NoneType”对象没有属性“find_element”

python selenium-webdriver automation browser-automation
1个回答
0
投票

检查您的“驱动程序”参数。目前错误指出, “NoneType”对象没有属性“find_element”。

_element_if_visible(driver.find_element(*locator)) ^^^^^^^^^^^^^^^^^^^ AttributeError:'NoneType'对象没有属性'find_element'

查看这几行代码,我们看到该对象是“driver”。

driver.find_element()

因此没有提供有效的驱动程序。

© www.soinside.com 2019 - 2024. All rights reserved.