首页 > 解决方案 > 测试错误:ElementClickInterceptedException

问题描述

我正在使用 Python 中的 Selenium 学习自动化测试。

我正在尝试测试一个 Web 项目,有一个创建页面,我编写了一个测试文件,它看起来是正确的,因为它在运行测试文件时大多会成功,但是具有相同代码的相同文件有时会失败(每个两次运行)

问题是什么?


代码:

import unittest
from unittestcase import TestRE
from common_functions import AddProperty
from locators import CommonPageLocators, SigninPageLocators, AddPropertyPageLocators
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import property_values as pv
import HtmlTestRunner
import time

class TestAddNewProperty01(TestRE):

    def setUp(self):
        super().setUp()
        self.add_property = AddProperty(self.driver)
        self.signout = AddProperty(self.driver)
        self.add_property.signin(SigninPageLocators.EMAIL_INPUT, SigninPageLocators.PASSWORD_INPUT, SigninPageLocators.LOGIN_BUTTON)
        self.driver.maximize_window()

    def test_add_new_property_01(self):
        self.add_property.add_property_button(AddPropertyPageLocators.ADD_PROPERTY_BUTTON)

        self.add_property.prop_name(AddPropertyPageLocators.PROPERTY_NAME, 'AddNewP01')
        self.add_property.prop_address(AddPropertyPageLocators.PROPERTY_ADDRESS, pv.address)
        self.add_property.investment_inflation(AddPropertyPageLocators.INVESTMENT_INFLATION, pv.investment_inflation_amount)
        self.add_property.investment_inflation_currency(AddPropertyPageLocators.INVESTMENT_INFLATION_CURRENCY, pv.investment_inflation_currency)
        self.add_property.repatriation_inflation(AddPropertyPageLocators.REPATRIATION_INFLATION, pv.repatriation_inflation_amount)
        self.add_property.repatriation_inflation_currency(AddPropertyPageLocators.REPATRIATION_INFLATION_CURRENCY, pv.repatriation_inflation_currency)
        self.add_property.analysis_start_date(AddPropertyPageLocators.ANALYSIS_START_DATE, pv.analysis_start_date)
        self.add_property.general_partner(AddPropertyPageLocators.GENERAL_PARTNER, pv.general_partner)
        
        self.add_property.default_rentable_space_designation(AddPropertyPageLocators.DEFAULT_RENTABLE_SPACE_DESIGNATION, pv.default_rentable_space_designation_type)
        self.add_property.identifier(AddPropertyPageLocators.IDENTIFIER)
        self.add_property.rentable(AddPropertyPageLocators.RENTABLE, pv.rentable_area)
        
        self.add_property.market_gross_rental_rate(AddPropertyPageLocators.MARKET_GROSS_RENTAL_RATE, pv.market_gross_rental_rate_amount)
        self.add_property.long_term_market_vacancy_rate(AddPropertyPageLocators.LONG_TERM_MARKET_VACANCY_RATE, pv.long_term_market_vacancy_rate_percent)
        self.add_property.overall_property_cap_rate(AddPropertyPageLocators.OVERALL_PROPERTY_CAP_RATE, pv.overall_property_cap_rate_percent)
        self.add_property.expected_inflation_rate(AddPropertyPageLocators.EXPECTED_INFLATION_RATE, pv.expected_inflation_rate_percent)
        self.add_property.landlord_discount_rate(AddPropertyPageLocators.LANDLORD_DISCOUNT_RATE, pv.landlord_discount_rate_percent)
        
        self.add_property.full_market_value(AddPropertyPageLocators.FULL_MARKET_VALUE, pv.full_market_value_amount)
        self.add_property.currency_symbols(AddPropertyPageLocators.CURRENCY_SYMBOLS, AddPropertyPageLocators.CURRENCY_SYMBOL)
        self.add_property.purchase_price(AddPropertyPageLocators.PURCHASE_PRICE, pv.purchase_price_amount)
        self.add_property.loan_to_value(AddPropertyPageLocators.LOAN_TO_VALUE, pv.loan_to_value_amount)
        self.add_property.interest_rate(AddPropertyPageLocators.INTEREST_RATE, pv.interest_rate)
        
        # self.add_property.operating_expenses(AddPropertyPageLocators.OE_NONCONT_TYPE, pv.oe_noncont_type_text, AddPropertyPageLocators.OE_NONCONT_RATE, pv.oe_noncont_rate_amount, AddPropertyPageLocators.OE_NONCONT_YOY, pv.oe_noncont_yoy_percent)
        # self.add_property.isCAM(AddPropertyPageLocators.OE_NONCONT_isCAM_input)
        
        self.add_property.improvements(AddPropertyPageLocators.IMPROVEMENT_TYPE, pv.improvement_type, AddPropertyPageLocators.IMPROVEMENT_COST, pv.improvement_cost)
        time.sleep(3)
        self.add_property.leasing_commissions(AddPropertyPageLocators.NEW_LEASE_RATE_PERCENT, pv.new_lease_rate_percent)
        time.sleep(3)
        self.add_property.leasing_commissions(AddPropertyPageLocators.RENEWAL_EXTENSION_RATE_PERCENT, pv.renewal_extension_percent)
        time.sleep(3)
        self.add_property.leasing_commission_methods(AddPropertyPageLocators.NEW_LEASE_METHOD, AddPropertyPageLocators.NL_METHOD_NET)
        time.sleep(3)
        self.add_property.leasing_commission_methods(AddPropertyPageLocators.RENEWAL_EXTENSION_METHOD, AddPropertyPageLocators.RE_METHOD_NET)
        
        self.add_property.click(AddPropertyPageLocators.SAVE_BUTTON)
        self.add_property.assert_elem_text(CommonPageLocators.HEADER_PAGE_NAME, 'Create Property') # final assertion1
        # self.add_property.assert_elem_text(CommonPageLocators.FINAL_FIRST_PROPERTY, 'AddNewP01') # final assertion2

if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='/home/khan/Projects/Automation Tests/REAuthomation/retop/results/html_pages/addnew'))


错误信息:

Unittest Results
Start Time: 2020-11-08 22:45:46

Duration: 25.76 s

Summary: Total: 1, Pass: 0, Error: 1

__main__.TestAddNewProperty01   Status  
test_add_new_property_01    
Error
ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (1195, 913). Other element would receive the click:

...
(Session info: chrome=85.0.4183.121)
Traceback (most recent call last): File "TCADDNEWP01.py", line 60, in test_add_new_property_01 self.add_property.leasing_commission_methods(AddPropertyPageLocators.RENEWAL_EXTENSION_METHOD, AddPropertyPageLocators.RE_METHOD_NET) File "/home/khan/Projects/Automation Tests/REAuthomation/retop/common_functions.py", line 215, in leasing_commission_methods WebDriverWait(self.driver, 20).until(EC.presence_of_element_located(method_locator)).click() File "/home/khan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "/home/khan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute return self._parent.execute(command, params) File "/home/khan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/khan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (1195, 913). Other element would receive the click:

...
(Session info: chrome=85.0.4183.121)
Total: 1, Pass: 0, Error: 1 -- Duration: 25.76 s

标签: pythonseleniumautomated-testsintegration-testing

解决方案


推荐阅读