'Search for a specific element in multiple pages and click using Python Selenium

Hi im trying to navigate from page 1 to page 5 (the element can be in any of the pages)and find and click on a specific element using python selenium. The following is the element from the page:

<span _ngcontent-mtx-c123"" class"ng-star-inserted">ABC Company</span>

i tried by using : driver.find_element_by_name("ABC Company").click() but this doesnt work. Another Way i tried:

1. element_path="//span[contains(text(),'ABC Company')]" 
2. while True: 
3.  if(driver.find_elements_by_xpath(element_xpath)): driver.find_element_by_xpath(element_xpath).click() 
4.  else: driver.find_element_by_xpath("xpath to goto next page").click()

I need the code to find element from the next pages until its found and then click it.

is there any other way to do this???

Thanks in Advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source