0

I am trying to automate the process of logging into a website and downloading reports.

When choosing which report to download you have to mouse over a menubar on the website and hovering the mouse over the right tab will open a pulldown menu where you then click the report you want.

Screenshot of the pulldown menu (sorry, but no points embed the image :( )

I have little experience with coding and I am very new to Python 3 so I am struggling on how to do this.

Using Selenium library I am able to find things such as the user and password fields and pass in the information to automatically log into the site. But not sure how to grab or point at the correct report in this pulldown menu in order to simpy click it.

Here is a snippet of the page source... the class name = rmText... and the class name is same for all of them... only the text inside the <span> is unique but I don't know how to grab that with the Python 3 code.

Screenshot of the page source

I know of a way to do this using VB script... but I would prefer to stay with Python 3 (and also learn how to do this via Python in the process). The example below was used for a similar report where multiple lines had same class-name and we needed just the one called "Infill". An example code of the VB script:

Set project = .Document.getElementsByClassName("UPC_Items")
    For Each elm In project
        If instr(elm.innerhtml,"Infill") then
            elm.Click
            Exit For
        End If
    Next    

How can I achieve the same using Python 3? And is Selenium the right library to use?

Thanks for reading and hopefully helping out a newbie in Python!

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • Please post the HTML as text instead of a picture. – JeffC Oct 07 '16 at 18:09
  • Possible duplicate of [How to mouseover in python Webdriver](http://stackoverflow.com/questions/11092748/how-to-mouseover-in-python-webdriver) – JeffC Oct 07 '16 at 18:12
  • While trying to copy the text to add to reply here I actually found out that Chrome lets you copy the xpath... I will try again using Selenium and the .find_elements_by_xpath(//*[@id="ctl00_MainMenu1"]/ul/li[7]/div/ul/li[6]/a/span['MCC'] . My goal is to click each report, like the MCC; RFCC and so on I think xpath might do the trick. – Roger Hansen Oct 10 '16 at 12:08

1 Answers1

0

try below code, hope this helps:

 from selenium import webdriver
 from selenium.webdriver.common.action_chains import ActionChains
 import time

 drive = webdriver.Firefox()
 driver.get('your url')
 ....
 steps to reach your place where that menu link is presert
 ....

 element = driver.find_element_by_class("rmText")

 putmouse = ActionChains(driver).move_to_element(element)
 putmouse.perform()
 time.sleep(2)
 texttoclick = driver.find_element_by_xpath(".//li[@class='rmText']//span[text()='MCC']")
 actions.move_to_element(texttoclick).click().perform()
thebadguy
  • 2,092
  • 1
  • 22
  • 31