seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.46k stars 909 forks source link

How can i click the element, not using selector #2762

Closed adarmawan117 closed 1 month ago

adarmawan117 commented 1 month ago

In a normal case, we can click a button like this: sb.click('//div[@aria-label="Pagination"]/a/button[@class="css-gtd0a9"]')

But, in another case, i need to fetch all elements, and click the latest element like this:

button_elements = sb.find_visible_elements('//div[@aria-label="Pagination"]/a/button[@class="css-gtd0a9"]')
button_elements[-1].click()
print(f"Count Button: {button_elements}")

Using Selenium, we can use: driver.find_elements(By.XPATH, 'selector')[-1].click()

adarmawan117 commented 1 month ago

I have found a solution to the problem above. sb.click('//div[@aria-label="Pagination"]/a[last()]/button/*[local-name() ="svg"]')

To get the last element, i can use XPATH instead of using the element itself.

But, if you want to add a new function, i really apreciate.