Webelements.IsMember modifications #43
Replies: 8 comments 6 replies
-
Having a quick explore at other classes you've got similar functionality for handling collections. Hinting at simple Collection wrapper for |
Beta Was this translation helpful? Give feedback.
-
+1 for the renaming to Exists, for analogy with VBA dictionaries If we're going to accept the deprecated use of errors as a shortcut, I'd try this:
Not sure about the performance gain of all both the suggested solutions though, they should be tested. |
Beta Was this translation helpful? Give feedback.
-
@MarkJohnstoneGitHub, did you mean to declare your Exists function as Private? Like @6DiegoDiego9, I think the name change is an improvement and also agree that "trafficking" in ElementId's breaks a design choice. It was decided early on in development that ElementId's would be hidden from the public-facing object model. I'm good with either of the proposed solutions, but Mark's will have to be modified to something like: Public Function Exists(element as WebElement) As Boolean
Dim key as string
key=element.ElementId 'friend property
... |
Beta Was this translation helpful? Give feedback.
-
@GCuser99 That might work with using a Collection wrapper with the Exists function. In the Implements section would refer to the Public Exists(element as WebElement) . As duplicating code in WebCookies a VBA.Collection wrapper would remove duplicated code. If no need for lists of keys or items should be reasonable easy to implement. Downside would have to change code to use the Collection wrapper interface in Webelements and WebCookies. |
Beta Was this translation helpful? Give feedback.
-
@MarkJohnstoneGitHub - how to keep code formatting? I enclose code block using three of the accent char (on same key as the ~, in the upper-left corner of my keyboard) followed by "vba" (without a space between the triple accents and vba) to open the block and then triple accents to close. I think a collection wrapper would be over-kill for this. Let's change the IsMember method to Exists. I'm not in favor of changing the input parameter "element as WebElement" to "key as WebElement" as the user shouldn't need to be aware how Exists works (collections and keys) but only that it DOES work. So presumably the coding problem we are trying to solve here (aside from the rename) is one of style (with only several thousand lines of code left to scrutinize! :-), and maybe efficiency... I'm ok with any of the Exists variants above, unless efficiency difference turns out to be significant (I doubt it). I like @6DiegoDiego9's version because it is succinct, and I can understand it at a glance. I also like your first iteration but with the modifications I suggested regarding the change to input parameter spec. PS: I like my original version too, but it's likely less efficient - I'd be curious to see how much less efficient! Can you test your proposed method against @6DiegoDiego9's, and my original for efficiency? Thanks for your suggestions and insights. BTW, are you able to run SeleniumVBA tests in MS Access yet? |
Beta Was this translation helpful? Give feedback.
-
@GCuser99 Will look at performance when get some time could be a few days. Offhand its VBA.Collection hashtable verses on average iterating half of the size of the collection. Consideration depending on the size of collection you're expecting as the larger it gets the more it effects performance. A VBA.Collection wrapper might be useful in other projects to help simplify code. |
Beta Was this translation helpful? Give feedback.
-
Anyway, the combinated need of Key handles and Exists method is usually a sufficient reason for me to use a Dictionary instead than a Collection. |
Beta Was this translation helpful? Give feedback.
-
@6DiegoDiego9 - no reason for it NOT being a dictionary. Although again, I'm having difficulty seeing what we are trying to solve here. Does a Collection fail in some way? Or is the Exists code so ugly and confusing that it needs a Dictionary (or a new Collection wrapper) to make it significantly easier to maintain? Or is there a significant efficiency problem? There are thousands of lines of code in this project, which I will be the first to admit is an amalgam of different and inconsistent styles (the original author of TinySeleniumVBA, an anonymous poster on that site who wrote a big chunk that was not incorporated into that project, myself, and you). The impetus when I got involved was to achieve near complete Selenium functionality as quickly as possible so I and others could use it! I think we are now close to achieving that goal (thanks again for your key contributions towards that!). Therefore, it makes sense next to try to standardize those contributions as far as style and maintainability - that's one of several reasons why I asked you if you were interested in helping. That is going to be a significant amount of work and I don't expect it to happen fast. I'm excited about tools like RubberDuck (thanks @MarkJohnstoneGitHub!) that will help us with that. However, our time is valuable, and we need to be selective on what we work on. I'm not in favor of making changes without compelling justifiable reasons. Finding a way to articulate justification for change, as a community, is what these discussions are very useful for - so I really appreciate the back and forth like above. As stewards we also need to be willing to balance our own (or any one individual user's) needs against the (potential) community of user's needs, with more weight on the later, IMO. I have a handful of ideas that I would like to add to SeleniumVBA to make it more useful to me, but I resist the urge to implement because if I'm honest, implementing some of these would probably not be very useful to most of that hypothetical community. Anyway, I apologize for what may seem like a rant - I'm just trying to explain above where I'm coming from when I may seem resistant or critical, when all I am sincerely trying to do is be a responsible steward - really! :-) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
A suggestion for the Webelements.IsMember function
It appears it could be more appropriately renamed to Exists .
The code appears inefficent and can simplified.
You only are required to pass in the string key i.e. element.id I'm not sure how you generated/acquire the initial ElementId key so far examining the code, not important atm, thou curious.
The below code should/not tested work.
I constructed it from the code below from my DictionaryKeyValuePair class. You don't require the EncodeKey related code as already have a String key and it converted various data types including objects to String keys.
https://github.com/MarkJohnstoneGitHub/VBA-IDictionary/blob/master/scr/DictionaryKeyValuePair.cls
Beta Was this translation helpful? Give feedback.
All reactions