Skip to content
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

add an alternative to find_by_text that looks at all inner text #862

Open
aekobear opened this issue Mar 11, 2021 · 4 comments
Open

add an alternative to find_by_text that looks at all inner text #862

aekobear opened this issue Mar 11, 2021 · 4 comments

Comments

@aekobear
Copy link

The current implementation of find_by_text uses the following xpath: //*[text()="some text"], which only looks at the first text node within an element. This makes it difficult to query for elements with text split across multiple text nodes.

I think it would be useful to add an alternative that acts more like element.textContent(), querying against all inner text of an element rather than its first text node. This can be done with the following xpath: //*[.="some text"]

It could be called find_by_text_content or find_by_inner_text or something along those lines.

I'm happy to do the implementation and make a pull request if people agree that there's a need / desire for this

@jsfehler
Copy link
Collaborator

This seems like something better served by an example in the documentation for now. Since it's essentially:

some_text = "some text spread across multiple elements"
find_by_xpath(f'//*[.="{some_text}"]')

A well documented example scenario showing the limitations of find_by_text with a solution would be helpful to anyone facing the same situation.

@stevelove
Copy link

I seem to have run into this also, where an HTML document had been built up like:

someElem.appendChild(document.createTextNode('some');
someElem.appendChild(document.createTextNode('text');
someElem.appendChild(document.createTextNode('spread');
...

In order to search for a single term in the middle of that content, this is the only XPath selector I've been able to get working in Splinter: //descendant::*/text()[contains(., "spread")].

I'm not an expert in XPath by any means, so it's possible there's a better selector; there were others that worked in the browser dev tools console, but not in Splinter. I tried the selector mentioned in the previous response and it didn't work for my scenario, so I wanted to add my solution to the mix.

@pratimugale
Copy link

Hi, is this issue up for grabs?

@sejalrj
Copy link

sejalrj commented Dec 9, 2023

Hi, is this issue still open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants