'Selenium - Get element after a specific element (Python)
As you can see from the picture, the pagination is a bit different. So my idea is to get the position of the current-page and get the link for the a tag.
current_page= driver.find_element(By.CSS_SELECTOR,"span.current-page")
driver.find_element(By.TAG_NAME,"a").click()
but I didn't know to use the current_page element to find the a tag after it and click on it.
Thanks for your help in advance.
Solution 1:[1]
To get the next element using current page reference you can use the following css selector in one liner or XPATH option.
next_page= driver.find_element(By.CSS_SELECTOR,"span.current-page+a")
print(next_page.get_attribute("href"))
next_page.click()
Or you can use this.
current_page= driver.find_element(By.CSS_SELECTOR,"span.current-page")
current_page.find_element(By.XPATH,"./following::a[1]").click()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KunduK |

