0

I have a webpage, and within it there is a menu that looks like this:

<span localization="" data-key="EXPORT_AND_IMPORT" class="ng-binding ng-isolate-scope">Export &amp; Import</span>

when I click it, it opens a sub menu with three options:

<div class="qmenu dropdown-menu positioned" style="top: 293px; left: 900px; max-height: 99%; width: 231px; height: 113px;"><ul class="menu-items"><li class="no-check"><a><i class="icon icon-download-lg"></i>Export Data...</a></li><li class="no-check"><a><i class="icon icon-uploadcsv-lg"></i>Import Data...</a></li><li class="divider"></li><li class="no-check"><a><i class="icon icon-twofiles"></i>Manage Previous Downloads...</a></li></ul></div>

here is a picture:

enter image description here

How can I press the Export & Import button and then the Export Data button with in the submenu?

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Moran Reznik
  • 699
  • 1
  • 6
  • 17

1 Answers1

0

First to click() on the element with text as Export & Import and then to click() on the submenu element with text as Export Data... you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.ng-binding.ng-isolate-scope[data-key='EXPORT_AND_IMPORT']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.qmenu.dropdown-menu>ul.menu-items li:nth-of-type(1)>a"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='ng-binding ng-isolate-scope' and @data-key='EXPORT_AND_IMPORT']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='qmenu dropdown-menu positioned']/ul[@class='menu-items']//li/a[contains(., 'Export Data')]"))).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