1
driver = webdriver.Firefox() 
driver.maximize_window() 
url = r"https://www.nba.com/stats/players/traditional" 
driver.get(url) 

advanced = driver.find_element(By.XPATH, r'//div[2]/div[2]/div[3]/section[1]/div/nav/div[3]/ul/li[2]/a')
action = ActionChains(driver)
action.move_to_element(advanced)
advanced.click()

return error is always: element could not be scrolled into view.

I've tried other versions of this code including:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//div[2]/div[2]/div[3]/section[1]/div/nav/div[3]/ul/li[2]/a'))).click()

Please help, Thank you already

3 Answers 3

1

You need to accept the cookie consent button and then click on of toggle to expand the dropdown and then select the element.

driver.get("https://www.nba.com/stats/players/traditional")
#accept cookie consent
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button#onetrust-accept-btn-handler"))).click()
time.sleep(1)
#expand
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"(//div[@class='StatsQuickNavSelector_nav__JzoME']/button)[last()]"))).click()
#click on specific item
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Advanced']"))).click()
Sign up to request clarification or add additional context in comments.

Comments

1

Try using:

element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//div[2]/div[2]/div[3]/section[1]/div/nav/div[3]/ul/li[2]/a')))

driver.execute_script("arguments[0].scrollIntoView();", element)

element.click()

To scroll the element into view. resource

2 Comments

raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Hi, thank you for the reply. When executing this code this is the return message I get. the "Message: " returns nothing.
1

A good study for clean understanding is below

    ele= driver.find_element(by=By.XPATH, value='//*[@id="elementid"]')

    action = ActionChains(driver)

    action.move_to_element(ele).click()

    action.send_keys(Keys.ARROW_DOWN)
    action.send_keys(Keys.ARROW_DOWN)
    action.send_keys(Keys.ARROW_DOWN)
    action.send_keys(Keys.ENTER)
    action.perform()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.