0

I am using Selenium with Python to download certain files from a website. I am trying to access a option called "View all products >>". From there, you could select the kind of file(csv, xlsx) and then you should download it easily. My problem is that I cannot access that "View all products" area. I've tried in so many ways. I'll attach my code and a screenshot with the structure of website. I cannot post entire HTML because it is a website restrictive only to it's paid users.

enter image description here. The five links:

  • 1 and 2. (Here "View All Products" appears twice):

     <a class="yui3-c-reportdashboardwidget-reportLink" href="./embedded.html?showGDLogo=false#project=/gdc/projects/e05jwlnny6rlxyt5ib9r6479279crrq8&amp;dashboard=/gdc/md/e05jwlnny6rlxyt5ib9r6479279crrq8/obj/4817&amp;tab=8473392139f7&amp;s=/gdc/projects/e05jwlnny6rlxyt5ib9r6479279crrq8|analysisPage|head|/gdc/md/e05jwlnny6rlxyt5ib9r6479279crrq8/obj/3630" title="Headline - View All Products Link" target="_self">Headline - View All Products Link</a>
    
  • 3 and 4. (Here "View All Products" appears twice):

     <span class="yui3-c-reportdashboardwidget-reportLabel" title="Headline - View All Products Link">Headline - View All Products Link</span>
    
  • 5:

     <div class="number" style="font-size: 16px; color: rgb(0, 61, 76);" id="yui_3_14_1_1_1540109592048_72886">      View all products &gt;&gt;</div>
    

The link that I want to handle is number "5", because I think that is the one I need to click(), so that I can download the report afterwards.

My code for this part:

View All Products Button

#product_button = driver.find_elements_by_xpath("//div[@class='c-oneNumberReport yui3-widget yui3-c-onenumberreport yui3-c-onenumberreport-content yui3-widget-content-expanded drillable']")[-1]
#product_button = driver.find_element_by_xpath(("//div[text()='View all products >>']"))
product_button = driver.find_elements_by_xpath("//a[@class='ember-view reportInfoPanelHandle point-to-top']")[-3]
product_button.click()
#product_button.send_keys(Keys.ENTER)
#####actions = ActionChains(driver)
#actions.move_to_element(product_button).send_keys(Keys.ENTER)
###########actions.move_to_element(product_button)
###########actions.click()
#actions.sendKeys(Keys.Return);
#actions.build().perform()

Update::::

enter image description here enter image description here

Here is the HTML for "Download As..":

<span class="button-text"><script id="metamorph-39-start" type="text/x-placeholder"></script>Download as...<script id="metamorph-39-end" type="text/x-placeholder"></script></span>

HTML for "CSV ( raw data)":

<ul id="ember2849" class="ember-view reportExportMenu gdc-menu-simple" style="position: absolute; top: 106px; left: 15px; z-index: 3005;"><li id="ember2850" class="ember-view reportExportMenuItem">
<a data-ember-action="17"><script id="metamorph-47-start" type="text/x-placeholder"></script>PDF (Portrait)<script id="metamorph-47-end" type="text/x-placeholder"></script></a>
</li><li id="ember2851" class="ember-view reportExportMenuItem">
<a data-ember-action="18"><script id="metamorph-48-start" type="text/x-placeholder"></script>PDF (Landscape)<script id="metamorph-48-end" type="text/x-placeholder"></script></a>
</li><li id="ember2852" class="ember-view reportExportMenuItem">
<a data-ember-action="19"><script id="metamorph-49-start" type="text/x-placeholder"></script>XLSX...<script id="metamorph-49-end" type="text/x-placeholder"></script></a>
</li><li id="ember2853" class="ember-view reportExportMenuItem">
<a data-ember-action="20"><script id="metamorph-50-start" type="text/x-placeholder"></script>CSV (formatted)<script id="metamorph-50-end" type="text/x-placeholder"></script></a>
</li><li id="ember2854" class="ember-view reportExportMenuItem">
<a data-ember-action="21"><script id="metamorph-51-start" type="text/x-placeholder"></script>CSV (raw data)<script id="metamorph-51-end" type="text/x-placeholder"></script></a>
</li></ul>
Community
  • 1
  • 1
PyRar
  • 539
  • 1
  • 4
  • 21
  • 2
    Is there one "View all products" link on page only? – Andersson Oct 21 '18 at 08:11
  • There are five, as I see.The one that I want to access has this structure: "
    View all products >>
    "
    – PyRar Oct 21 '18 at 08:15
  • 2
    And how about other links? They have the same HTML? – Andersson Oct 21 '18 at 08:18
  • With exact index. But it's weird. For example when I run one of the xpath :#product_button = driver.find_elements_by_xpath(("//div[text()='View all products >>']")) it just says that the element not interactable – PyRar Oct 21 '18 at 08:18

1 Answers1

1

Try to use below code to click required element:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait

link = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//div[starts-with(normalize-space(), "View all products")]')))
driver.execute_script("arguments[0].scrollIntoView();", link)
link.click()
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • It gave me this Exception: "WebDriverException: unknown error: Element is not clickable at point (1448, 958)" – PyRar Oct 21 '18 at 08:57
  • 1
    Try updated answer. Does it work now? Also share complete exception. DOes it looks like *"..another element receives the click..."*? – Andersson Oct 21 '18 at 09:00
  • Yes! Thank you!! If I put 2 screenshots of how it looks now can you advise me very shortly how to write the code to press: "Download As..." and afterwards from dropdown "CSV (raw data)"? I'll update the post now. – PyRar Oct 21 '18 at 09:09
  • 1
    Hmm... Try something like `wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[starts-with(., "Download as")]'))).click()` and then `wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[. ="CSV (raw data)"]'))).click()` – Andersson Oct 21 '18 at 09:20
  • Hello Andersson! Just one more question. If I want to click on that "View all Products >>" and not on that Arrow(pointing downwards) above it, how do I proceed with that? – PyRar Oct 24 '18 at 07:34
  • Try XPath `//span[.="Download as..."]` – Andersson Oct 24 '18 at 07:38
  • It gives me : "NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//span[.='Download as...']"}". But I don't search the "Download As". If you look at the picture from the post, for the moment we click at that circle with a arrow above "View all Products >>". Now I need to click directly on that "View all Products >>" and not on that circle above it. – PyRar Oct 24 '18 at 07:52
  • @user7362809 , oh, so you mean that when you're trying to click element with XPath `//div[starts-with(normalize-space(), "View all products")]` actually the round arrow button intercepts the click? – Andersson Oct 24 '18 at 07:57
  • Yes sir @Andersson! That's what is happening for the moment. Don't really know why... – PyRar Oct 24 '18 at 07:59
  • @user7362809 , you can try either [click with offset approach](https://stackoverflow.com/questions/16807258/selenium-click-at-certain-position) which is preferable way or using JavaScript to make that arrow button just disappear. You can also open new ticket regarding this new issue – Andersson Oct 24 '18 at 08:06
  • I will try firstly with offset approach! Thank you! If it doesn't work I'll open a new ticket. – PyRar Oct 24 '18 at 08:09
  • Hello again @Andersson! I've observed one thing. On my laptop(which has a 14' inch display) selenium clicks on that round arrow button. But if I move the output windows of chrome on the other monitor(24' inch) it clicks just right on the "View all Products >>" button. I've tried with offset approach but can't get it right. This is what I've wrote: "action = webdriver.common.action_chains.ActionChains(driver) action.move_to_element_with_offset(link, 40, 30) action.click() action.perform()" Basically, the round arrow is 25 x 25 pixels – PyRar Oct 24 '18 at 08:53
  • @user7362809 , `40`, `30` is too much. Try just few (`1` - `3`) pixels down – Andersson Oct 24 '18 at 08:56
  • I've tried with 1,2,3 but it doesn't work :( It doesn't click anywhere I think... – PyRar Oct 24 '18 at 09:02
  • @user7362809 , try to set window size explicitly `driver.set_window_size(1920, 1080)` to force same behavior on desktop and laptop, but I'm not sure that it will work... – Andersson Oct 24 '18 at 09:17