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

Finding partial text #608

Open
Qqwy opened this issue Apr 28, 2018 · 4 comments
Open

Finding partial text #608

Qqwy opened this issue Apr 28, 2018 · 4 comments

Comments

@Qqwy
Copy link

Qqwy commented Apr 28, 2018

It is very common that you want to look for a snippet of text, rather than a text element that as a whole contains exactly what you look for; like when looking for a username on a page.

The current browser.is_text_present however only matches a text element 1:1. (and the documentation about this is not very clear that this is what is going on).

So if we have

<h1>Welcome, DeathSlayer!</h1>

Then browser.is_text_present("DeathSlayer") will return false, as will browser.is_text_present("Welcome, DeathSlayer") (because of the missing exclamation mark).

Could another command be introduced for this?

@andrewsmedina andrewsmedina added this to the after 1.0 milestone Aug 27, 2018
Murkantilism added a commit to Murkantilism/splinter that referenced this issue Oct 13, 2018
I'm on a windows machine so I cannot set up a dev environment to test this myself, if @Qqwy or someone else can test this implementation for me I would appreciate it.
@BhavishyaJain
Copy link

@andrewsmedina Hi, is anyone working on this? if not, then can I take it up?

@Vichoko
Copy link

Vichoko commented Apr 15, 2019

Bump this. I think is a crucial feature, because text is not always known completely. For achiving this, maybe regex could be a very nice input to represent lookup in a more flexible way.

@abathur
Copy link

abathur commented Oct 21, 2019

I was having trouble matching some text and saw this issue while looking for possible explanations. It may just be a version difference (I'm using 0.11.0) since this was opened, or perhaps I'm using a different driver, but I don't see this behavior with is_text_present.

I can match partial text just fine.

FWIW, the problem I was having was with matching text that spanned more than one element. I looked at the implementation and see that it's just calling roughly splinter.driver.find_element_by_tag_name("body").text.index(needle). In my case, checking the contents of splinter.driver.find_element_by_tag_name("body").text helped me identify what I needed to match against.

Edit: I did notice, however, that find_by_text (and methods that depend on it like is_element_present_by_text and is_element_not_present_by_text) compiles down into an xpath query that will only match the entire node's exact text.

@LexaDS
Copy link

LexaDS commented Sep 10, 2020

Do not know if this issue was solved, but what about the contains() function in XPath, might help with the whole partial text issue.

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

6 participants