简体   繁体   English

如何在 python selenium 中解决此错误我收到的错误消息是 TypeError: Object of type method is not JSON serializable

[英]How to solve this error in python selenium the error message that I am getting is TypeError: Object of type method is not JSON serializable

I am getting this error when clicking on a submenu under a parent menu, please help me out to solve this problem, The error occurs when the script calls the 'Submenu method'单击父菜单下的子菜单时出现此错误,请帮我解决此问题,脚本调用“子菜单方法”时发生此错误

enter code here

This below class contain all the locators of the page下面的这个类包含页面的所有定位器

class workflow_locator:
    # Create a new workflow locator
    dropdown_xpath = "(//DIV[@class='btn-group dropdown'])[1]"
    admin_menu_xpath = "(//A[@class='dropdown-item'])[3]"
    breadcrumb_xpath = "(//DIV[@class='left-menu-toggle'])[1]"
    workflow_menu_xpath = "(//A[@_ngcontent-ng-cli-universal-c5=''])[31]"
    workflow_submenu_xpath = "(//A[@href='/admin/workflows'])"
    new_btn_xpath = "(//DIV[text()=' New'])"
    workflow_name_xpath = "(//INPUT[@id='name'])[1]"
    workflow_description_xpath = "(//TEXTAREA[@id='description'])[2]"
    active_toggle_xpath = "(//SPAN[@class='slider'])"
    add_button_xpath = "(//BUTTON[@class='btn btn-primary btn-sm'])[text()='Add']"


#This class define the action method of the below test class
from Resources.Workflow_locator import workflow_locator
class CreateWorkflow(workflow_locator):
    def __init__(self, driver):
        self.driver = driver

    def click_drop_down_menu(self):
        self.driver.find_element_by_xpath(self.dropdown_xpath).click()

    def select_admin_from_the_drop_down_menu(self):
        self.driver.find_element_by_xpath(self.admin_menu_xpath).click()

    def click_breadcrumb_menu(self):
        self.driver.find_element_by_xpath(self.breadcrumb_xpath).click()

    def click_workflow_menu(self):
        self.driver.find_element_by_xpath(self.workflow_menu_xpath).click()
    def click_workflow_sub_menu(self):
        self.driver.find_element_by_xpath(self.click_workflow_sub_menu).click()

# This is a test class
     def test_workflow(self, setup):
            self.driver = setup
            self.driver.get(self.base_url)
            self.driver.maximize_window()
            self.lp = Login(self.driver)
            self.lp.set_Username(self.username)
            self.lp.click_next_btn()
            self.lp.set_password(self.Password)
            self.lp.click_signin_btn()
            self.lp.click_confirm_btn()
            self.driver.get_screenshot_as_file(".\\Screenshoots\\login.png")
            self.logger.info("############ User is successfully logged in ########### ")
            print("Login is successfully completed")
            self.logger.info("######### Creating WorkFlow #########")
            self.wf=CreateWorkflow(self.driver)
            self.wf.click_drop_down_menu()
            self.wf.select_admin_from_the_drop_down_menu()
            self.wf.click_breadcrumb_menu()
            self.wf.click_workflow_menu()
            self.wf.click_workflow_sub_menu()

The exception I can see is我能看到的例外是

def default(self, o): """Implement this method in a subclass such that it returns a serializable object for o , or calls the base implementation (to raise a TypeError ). def default(self, o): """在子类中实现这个方法,以便它为o返回一个可序列化的对象,或者调用基本实现(引发TypeError )。

    For example, to support arbitrary iterators, you could
    implement default like this::

        def default(self, o):
            try:
                iterable = iter(o)
            except TypeError:
                pass
            else:
                return list(iterable)
            # Let the base class default method raise the TypeError
            return JSONEncoder.default(self, o)

    """
 raise TypeError(f'Object of type {o.__class__.__name__} '
                    f'is not JSON serializable')

E TypeError: Object of type method is not JSON serializable E TypeError: 类型方法的对象不是 JSON 可序列化的

enter image description here在此处输入图片说明

You have:你有:

def click_workflow_menu(self):
    self.driver.find_element_by_xpath(self.workflow_menu_xpath).click()
def click_workflow_sub_menu(self):
    self.driver.find_element_by_xpath(self.click_workflow_sub_menu).click()

When you call self.click_workflow_sub_menu() , this is what happens:当您调用self.click_workflow_sub_menu() ,会发生以下情况:

  1. self.click_workflow_sub_menu is evaluated. self.click_workflow_sub_menu被评估。 But this evaluates to a bound method and not a valid xpath expression.但这评估为绑定方法而不是有效的 xpath 表达式。
  2. self.driver.find_element_by_xpath is invoked with the result from step 1, which is not a valid xpath expression, and an exception results. self.driver.find_element_by_xpath使用步骤 1 的结果调用,该结果不是有效的 xpath 表达式,并导致异常。

I believe that is your problem.我相信这是你的问题。 What you probably meant was:你的意思可能是:

def click_workflow_sub_menu(self):
    self.driver.find_element_by_xpath(self.workflow_submenu_xpath).click()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到类型错误JSON无法序列化 - I am getting Type Error JSON is not serializable TypeError:RelativeBy 类型的 Object 不是 JSON 使用 relative_locator 到 Selenium2378217936B9 的可序列化错误 - TypeError: Object of type RelativeBy is not JSON serializable error using relative_locator through Selenium Python TypeError: Object of type RelativeBy is not JSON serializable error using Selenium 4's Relative Locator with Python 3 - TypeError: Object of type RelativeBy is not JSON serializable error using Selenium 4's Relative Locator with Python 3 错误:TypeError:ColumnClause 类型的对象不是 JSON 可序列化的 Python3 - ERROR: TypeError: Object of type ColumnClause is not JSON serializable Python3 Python 错误:TypeError:'Timestamp' 类型的对象不是 JSON 可序列化的' - Python error : TypeError: Object of type 'Timestamp' is not JSON serializable' 获取错误:用户类型的对象在 django python 中不是 JSON 可序列化的 - Getting error : Object of type User is not JSON serializable in django python TypeError:TypeError 类型的对象不是 JSON 可序列化的 Python - TypeError: Object of type TypeError is not JSON serializable Python TypeError:Tensor 类型的对象不是 JSON 可序列化的 - Pytorch 中的 json 错误 - TypeError: Object of type Tensor is not JSON serializable - dict to json error in Pytorch 如何修复日期时间类型的 Object 中的 Python 不是 JSON 可序列化错误 - How to fix Python at Object of type datetime is not JSON serializable error 我收到此错误消息:TypeError: 'function' object is not iterable - I am getting this error message: TypeError: 'function' object is not iterable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM