I post the XPATH and CSS SELECTOR paths here to make it easier for an answer. I can use any of the those. No particular choice.
My steps would be: (just for interesting sake)
R/Click the EDIT button β opens new webpage - execute some code β come back to the original webpage β click DELETE button β execute some code. Then repeat the same steps.
The EDIT and DELETE buttons are on the same webpage.
I run Python3 in Centos8 to scrape a website with Firefox that contains these examples above.
I have no code to show what I have tried as this is beyond my knowledge.
unfortunately, it is not really clear what you want to achieve once you have found the highest number. You edit something and then delete it?
It would be helpful if you could let us know the website if it is not private.
With selenium you can test web applications and automate actions like clicking, filling input fields and checking for results.
Thank you and Sorry about that. Below I rephrased the question.
Find XPATH or CSS SELECTOR with highest number
SCENARIO:
I need to find the element from a webpage with the highest number in the string. This is the last element on the web page.
The highest value as in the example below is 1000. This highest number can vary anything between 1 - 10 000 depending on how many items there are on the website.
The EDIT and DELETE buttons have the SAME NUMBER as they refer to the same item on the web page. (1000 items in this case) The last element having the highest nr.
(I inluded the CSS Selector and XPATH to provide more informatin. I can use one or the other. I have no prefference)
My steps would be:
Loop through webpage to find the last (EDIT BUTTON) element. The one with the highest value ie: 1000
Execute some of my own Python code
Loop through the sae web page again to find the last (DELETE BUTTON) element. One with the highest value ie: 1000
Execute some of my own Python code which will finally delete the last element. This action will remove the last item from the web page and thus the last EDIT and DELETE buttons as well.
The last available elements will now be 999 (1000 minus 1)
Loop through webpage to find the last element (EDIT BUTTON). 999
Execute some of my own Python code
Loop through webpage to find the last element (DELETE BUTTON). 999
Execute some of my own Python code which will finally delete the last item and elements.
The last available elements will now be 998 (999 minus 1)
Repeat loops and own code again as above
Loop until there are no more elements left to process.
In a nutshell:
Find last element on web page β click EDIT Button β run own Python code β click DELETE button - run own Python code -loop to find last available element on web page - click EDIT Button β run own Python code β click DELETE button β run own code β loop to find last available element β click EDIT button β¦ etc etc.
The EDIT and DELETE buttons are on the same webpage.
CODE:
I NEED HELP WITH THE FOLLOWING CODE PLEASE:
To find the last EDIT BUTTON element (one with the highest value)
Provide a slot in code for me to run other code
Loop to find the last DELETE BUTTON element.
Provide a slot in code for me to run other code
Return to top of loop again.
I run Python with Selenium code on Centos8 to scrape a website with Firefox that contains these examples above.
I canβt find any similar examples anywhere. Not in Selenium or Python pages/help files.
I have no code to show what I have tried as this is beyond my knowledge.
I found a solution.
Used the and to find the element.
Searched for the icon/button txt.
Finds last DELETE BUTTON from Webpage:
browser.find_elements_by_css_selector("div[class='delete'] span[class='icon-delete-item']") [-1].click()
Finds last EDIT BUTTON from webpage:
browser.find_elements_by_css_selector("div[class='manage-action'] span[class='icon-edit-item']") [-1].click()
Code explanation:
("div[class='delete'] = searches for all the div classes that contains the txt "icon-delete-item".
span[class='icon-delete-item'] = searches for all the span class items that contains the txt "delete". In this case it's an icon/button with the name 'icon-delete-item'
The [-1] at the end means the last one. In this case the last one at the bottom of the Webpage.
If one replace the [-1] with [10] it will find the 10th element from the top.
Or the [-1] option can also be used when one searches a list and wants to find the last entry in a list.