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 __getitem__ to XPathLocator #109

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

M1troll
Copy link
Contributor

@M1troll M1troll commented Feb 10, 2025

Add ability to get related xpath locators by index

# To avoid ugly locators with `...)[last() - 0]`
query += "[last()]"
else:
query += f"[last() - {abs(index + 1)}]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems -index+1 is enough for this case, cuz due to conditions index can only be (-inf;-2]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can
But I just decided to use the current variant because if we leave the -index+1 option, we get a less readable query:

index = -2
f"[last() - {abs(index + 1)}]"  --> [last() - 1] "

f"[last(){index + 1}]"  --> [last()-1] "  <-- *no spaces, harder to read

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤙🏻

@M1troll M1troll force-pushed the feature/add-getting-by-index-to-xpathlocator branch from e886b39 to 333d98d Compare February 11, 2025 08:39
Add ability to get related xpath
locators by index
@M1troll M1troll force-pushed the feature/add-getting-by-index-to-xpathlocator branch from 333d98d to c6554f7 Compare February 11, 2025 08:41
@M1troll M1troll merged commit 3b119ac into main Feb 11, 2025
1 check passed
@M1troll M1troll deleted the feature/add-getting-by-index-to-xpathlocator branch February 11, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants