Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:41:31+00:00 2026-06-07T08:41:31+00:00

I’m trying to create a think proxy using the __get__ descriptor over a certain

  • 0

I’m trying to create a think proxy using the __get__ descriptor over a certain type of data so that it can be used conveniently by client code (best shown with an example):

class Value(object):
    def __init__(self, val):
        self.val = val
    def __get__(self, instance, owner):
        return self.val

class Container(object):
    x = Value(1)
    y = [ Value(2), Value(3) ]

c = Container()
assert c.x == 1
assert c.y[0] == 2 # fails.

Now, I mostly see why it fails, so I’m wondering if theres a better way to achieve my goal which is wrap up the data so that when the client accesses it they simply have to access the Value object directly (in reality, the __get__ method would do something with self.val before returning it)

Details

The actual case I’m trying to tackle is utility code to assist in writing PageObjects & PageElements for selenium test cases. What I want to provide is a clean and simple way for test authors to write PageObjects of the form:

class MyLogin(PageObject):
    username_text_box = PageElement(By.ID, "username")
    password_text_box = PageElement(By.ID, "password")
    submit_button = PageElement(By.CLASS_NAME, "login-button")

driver = webdriver.Firefox()
driver.get("http://mypage.com")
login_page = MyLogin(driver)
login_page.username_text_box.send_keys("username01")
login_page.password_text_box.send_keys("XXXX")
login_page.submit_button.click()

I’m trying to encapsulate the business of fetching the actual WebElement inside the PageElement class and I want to allow the client to have access to the WebElement once they access the PageElement Object. Being able to have lists, dictionaries assists in making the PageObject instance clearer and to group related PageElements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:41:32+00:00Added an answer on June 7, 2026 at 8:41 am

    I settled with an implementation which both jsbueno & python_noob were approaching. However both their implementations don’t meet my criteria of allowing test authors to write simple declarative page object.

    import inspect
    import weakref
    class Value(object):
        def __init__(self, val):
            self.val = val
        def __get__(self, instance, owner):
            return self.val
    
    def get_value_from_proxy(obj, inst):
        if isinstance(obj, Value):
            return obj.__get__(inst, inst.__class__)
        else:
            return obj 
    
    class ValueList(list):
        def __init__(self, instance, *args, **kwargs):
            list.__init__(self, *args, **kwargs)
            self.instance = weakref.ref(instance)
        def __getitem__(self, idx):
            return get_value_from_proxy(list.__getitem__(self, idx), self.instance() )
    
    class ValueDict(dict):
        def __init__(self, instance, *args, **kwargs):
            dict.__init__(self, *args, **kwargs)
            self.instance = weakref.ref(instance)
        def __getitem__(self, key):
            return get_value_from_proxy(dict.__getitem__(self, key), self.instance() )
    
    class BaseContainer(object):
        def __init__(self):
            for el in inspect.getmembers(self):
                if isinstance(el[1],list):
                    setattr(self, el[0], ValueList(self, el[1]))
                elif isinstance(el[1],dict):
                    setattr(self, el[0], ValueDict(self, el[1]))
    
    
    class Container(BaseContainer):
        x = Value(1)
        y = [ Value(2), Value(3) ]
        z = {"test":Value(4)}
    
    c = Container()
    assert c.x == 1
    assert c.y[0] == 2
    assert c.z["test"] == 4 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.