Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to locate the pagination select button using Python Selenium

Code trials:

from selenium import webdriver 
from selenium.webdriver.support.ui import Select 
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import pandas as pd

driver = webdriver.Firefox()

url = r"https://www.nba.com/stats/players/advanced"
driver.get(url) 

select = Select(driver.find_element(By.XPATH, r"/html/body/div[2]/div[2]/div[2]/div[3]/section[2]/div/div[2]/div[2]/div[1]/div[3]/div/label/div/select"))

select.select_by_index(0) 

No matter everything I try I cannot find this full Xpath. I just want the code to recognise the little button that goes from page 1 to all to view all player stat on single page.

I’ve looked into similar questions but unable to get it solved.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Snapshot:

snapshot

>Solution :

When it seems that the path is not working, the better way to start solving the problem is to gradually remove tags from left to right while in the inspector tool. By removing /html/body/div[2] from your xpath I was able to find the element in the HTML

xpath = "//div[2]/div[2]/div[3]/section[2]/div/div[2]/div[2]/div[1]/div[3]/div/label/div/select"
select = Select(driver.find_element(By.XPATH, xpath))

which if I understood correctly is this one

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading