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

KunduK
  • 32,888
  • 5
  • 17
  • 41
de4dhe4d00
  • 29
  • 7

3 Answers3

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

kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21
  • raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: – de4dhe4d00 Jan 20 '23 at 09:36
  • Hi, thank you for the reply. When executing this code this is the return message I get. the "Message: " returns nothing. – de4dhe4d00 Jan 20 '23 at 09:36
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()
KunduK
  • 32,888
  • 5
  • 17
  • 41
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()
Hamit YILDIRIM
  • 4,224
  • 1
  • 32
  • 35