-
-
Notifications
You must be signed in to change notification settings - Fork 60
Added functionality to locate elements based on any combination of their tagname, attributes, and text value. #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e and return multiple elements
…nd iframes, and adding the functionality to search either by text, or using a tagname and a dictionary of attributes
…s for a more efficient way to find elements, users have total control over which method they want to search; either by tagname, attributes, or text
…attributes, or both
…e into attrs dictionary, ex: attrs['innerText'] = textValue
…h any combination of tagname, attrs, and text
…ntifying elements
… the new functions. modifying wait_for to work with the new functions. also, bug fixes
…les the logic of finding elements, instead of duplicating the logic; now find_element_by_tagname_attrs_text and find_elements_by_tagname_attrs_text call _find_elements_by_tagname_attrs_text with an argument return_after_first_match indicating whether we're aiming for a single element, or a list of elements
@stephanlensky I might need your help resolving conflicts in this pull request. I did what I could without breaking the existing functionality. |
Hey Hamza, I resolved all of the conflicts and did some small cleanups on a new branch here: https://github.com/stephanlensky/zendriver/tree/hamzaiitbrik/main Feel free to update your fork to use that branch, I cannot do it on my end since the fork is in your account. However, I noticed that this is probably not actually working as intended. For example, this test is failing:
This is because your code is returning the <ul>
<li aria-label="Apples (42)">Apples</li>
<li>Bananas</li>
<li>Carrots</li>
<li>Donuts</li>
<li>Eggs</li>
<li>French Fries</li>
<li>Grapes</li>
<ul> Hopefully it is clear why returning |
Hello @stephanlensky, you actually did a typo on my name and added an additional "i," it's hamzaaitbrik instead of hamzaiitbrik. Could you please fix that? As for the test, I just inspected the Thanks, |
Whoops, I'm sorry I actually just linked the wrong test. This is the one that's failing. Sorry for the typo as well, I pushed a new branch here: https://github.com/stephanlensky/zendriver/tree/hamzaaitbrik/main |
You should be able to replicate the failure locally by running |
Omg, my copy key isn't working, I keep linking the wrong thing. One second, sorry |
Okay, fixed now. For posterity, here is the correct link: https://github.com/stephanlensky/zendriver/blob/hamzaaitbrik/main/tests/core/test_tab.py#L36-L43 |
Haha, no worries! Take your time, and let me know what's up when you're done. |
Hello @stephanlensky. It took me a while to answer, got little to no free time.. Anyway, I did some debugging to pinpoint where the problem was; and what I found is that the parent element's text returns the child element's text; and that's why when the To try and dig a little bit deeper, I added more code to check if our element that we found by text has children, and those children has the text value we're looking for, and if so; we simply ignore the parent element and return the child. The code is as follows: # sometimes the parent element is preceived as the element holding the text content while it actually the child that does so, below is the code to handle that situation
if (
text and matches_text and elem.children
): # we only check for children containing the text if text was provided and elem.children exists
# if elem.children:
for child in elem.children:
if text in child.text.strip().lower():
elem = child
break The above code was added in the I also added another function in the Let me know what you think. Regards, |
Hi Hamza, Sorry for the long delay, I was dealing with some things IRL. I just took a look at this again, and also merged in the latest changes to your fork for you. Unfortunately it seems like some of the tests are still failing. Have you tried to run them locally? You can do so like
I am trying to spend some more time on this project again, so I will hopefully be able to respond more quickly in the future. |
This pull request was automatically closed because it has been inactive for 7 days since being marked as stale. |
Hello @nathanfallet, I'm still interested in merging this since it's a big issue of the web automation community; what do you think? |
@hamzaaitbrik Yes this is still a great idea! Is it a WIP or is it ready for review? Since the PR is here for so long I don't know if you had more things to do on it or not 🤷♂️ |
@nathanfallet I think it needs more work since I tried the newer version of zendriver with my modifications and it threw me a bunch of errors; no biggie, I can modify on those functions to make it work again. |
Hello @stephanlensky. Here's another pull request prior to the last one.
I couldn't resolve the conflict between the base repository and my fork. The conflict between the two branches is in the functions I added/removed/modified. I'll leave resolving the conflicts to you if you don't mind.
Feel free to review the code, and let me know what you think.
Thanks,
Hamza