0

I want to press the green download button from this website: https://www.wikiloc.com/wikiloc/download.do?id=41057284

using selenium chrome driver. However nothing works.

I tried searching by xpath:

clone_box = driver.find_element_by_xpath('//*[@id="btn-download-file"]')

the selector:

clone_box = driver.find_element_by_xpath('#btn-download-file')

class names:

clone_box = driver.find_element_by_class_name('btn btn-lg btn-success')

Does Not work. Further investigation lead me to so called frame/iframe.

following code suppose to switch it to:

driver.switch_to_frame(driver.find_element_by_id("download-option"))

But it also doesn't work .

The question is, where is that frame/iframe ? and how to switch to it ?

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Ad.blu
  • 1
  • 2
  • The green button has id `get-the-app`, not `btn-download-file`. And I don't see any ` – Guy Sep 10 '19 at 07:14

1 Answers1

0

To click() on the element you have to bring the element within the Viewport inducing WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using LINK_TEXT:

    driver.get("https://www.wikiloc.com/wikiloc/download.do?id=41057284")
    driver.execute_script("scroll(0, 250)");
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Get the App"))).click()
    
  • Using CSS_SELECTOR:

    driver.get("https://www.wikiloc.com/wikiloc/download.do?id=41057284")
    driver.execute_script("scroll(0, 250)");
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-lg.btn-success[onclick^='ga']"))).click()
    
  • Using XPATH:

    driver.get("https://www.wikiloc.com/wikiloc/download.do?id=41057284")
    driver.execute_script("scroll(0, 250)");    
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='btn btn-lg btn-success' and text()='Get the App']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • I tried all of them, however I get: "selenium.common.exceptions.TimeoutException: Message: " I also tried to increase the timeout value. No luck here. – Ad.blu Sep 10 '19 at 07:23
  • @Ad.blu Try out the updated answer and let me know the status – DebanjanB Sep 10 '19 at 07:43
  • So "driver.execute_script("scroll(0, 250)")" throws an error: selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value' (Session info: headless chrome=76.0.3809.132) (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.17763 x86_64). hmm – Ad.blu Sep 10 '19 at 08:15
  • Hmm, you are using **chrome=76.0**, you should be using **chromedriver=76.0** but not _chromedriver=2.33_ – DebanjanB Sep 10 '19 at 08:19
  • My mistake, I corrected the version, now it runs smooth, but I cannot find the file anywhere – Ad.blu Sep 10 '19 at 08:26
  • Also, when I execute the script, chrome driver shows this page: https://www.wikiloc.com/outdoor-navigation-app – Ad.blu Sep 10 '19 at 08:57
  • @Ad.blu That is exactly what happens when you click on the element manually :) – DebanjanB Sep 10 '19 at 09:04
  • I understand, but I do not want to press get the app, but rather download. I have written the script to log in to the website and it works. This is what I get: https://ibb.co/w7PkPsL How do I switch to the file tab ? – Ad.blu Sep 10 '19 at 09:11
  • How can any contributor help you to download if downloading isn't enabled for non registered users? We don't have a visibility either to your _log in_ script or HTML after logging in. – DebanjanB Sep 10 '19 at 09:18