-3

I'm trying to extract past one year prices.

Source Image

Unable to get the XPath for the drop down.

Here's my recent code:

element1 = driver.find_element_by_xpath("""//button[@title="1 year"]""")
element2 = driver.find_element_by_xpath("""//*[@id="chartmenu"]/li/a""")

hoverover = ActionChains(driver).move_to_element(element1).move_to_element(
    element2).click().perform()

Where am I wrong here? Please help!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
PratikSharma
  • 321
  • 2
  • 17

2 Answers2

0

Wait and check success login, than try to download. Here improved code:

driver.find_element_by_xpath("//input[@type = 'email']").send_keys(************)
driver.find_element_by_xpath("//input[@type = 'password']").send_keys(*********)
driver.find_element_by_name("go").click()
# wait until success login, by waiting some element on home page

driver.get('https://www.deribit.com/prinx_chart')
driver.find_element_by_xpath("//button[@title='1 year']").click()
driver.find_element_by_css_selector("span[data-i18n='app.price_index_csv_download']").click()
Sers
  • 12,047
  • 2
  • 12
  • 31
  • I get the following: `NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[data-i18n='app.price_index_csv_download']"}` – PratikSharma Aug 11 '19 at 17:24
0

To click() on the dropdown element with text as Download Price Index CSV you need you have to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategies:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.action_chains import ActionChains
    
    chrome_options = webdriver.ChromeOptions() 
    chrome_options.add_argument("start-maximized")
    driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://www.deribit.com/prinx_chart")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.btn-group.btn-group-sm button[title='1 year']"))).click()
    download_element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.highcharts-container ")))
    ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a.dropdown-toggle")))).perform()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "ul#chartmenu a[href*='PrChart'] span[data-i18n*='price_index_csv_download']"))).click()
    
  • Browser Snapshot:

BTC

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352