2
votes

I want to click the excel button under export drop down button.But even I am able to access the menu.When I am trying to click on the excel option under it,a message is being displayed that unable to locate element.

Here is the exact error message: Traceback (most recent call last): File "C:/Users/shishir sinha/PycharmProjects/australia/australia.py", line 33, in driver.find_element_by_xpath(".//[@id='ui-menu-0-1']").click() File "C:\Users\shishir sinha\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 309, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Users\shishir sinha\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 787, in find_element 'value': value})['value'] File "C:\Users\shishir sinha\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in execute self.error_handler.check_response(response) File "C:\Users\shishir sinha\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":".//[@id='ui-menu-0-1']"} (Session info: chrome=58.0.3029.110) (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.14393 x86_64)

Here is the link to website: https://stats.oecd.org/Index.aspx?DataSetCode=STAN08BIS

Here is the code:

 _author_ = 'shishir'
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC



driver=webdriver.Chrome("C:\\Users\\shishir sinha\\AppData\\Local\\Programs\\Python\\Python36\\selenium\\webdriver\\chromedriver_win32\\chromedriver.exe")
driver.get("https://stats.oecd.org/Index.aspx?DataSetCode=STAN08BIS")



driver.find_element_by_xpath(".//*[@id='PDim_COU']").click()
driver.find_element_by_xpath(".//*[@id='PDim_COU']/option[1]").click()
WebDriverWait(driver,20).until(EC.visibility_of_element_located((By.XPATH, ".//*[@id='PDim_VAR']")))
driver.find_element_by_xpath(".//*[@id='PDim_VAR']").click()

action = webdriver.ActionChains(driver)


driver.find_element_by_xpath(".//*[@id='PDim_VAR']/option[3]").click()



WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, ".//*[@id='menubar-export']/a/span[1]/span[2]")))
driver.find_element_by_xpath(".//*[@id='menubar-export']/a/span[1]/span[2]").click()
driver.find_element_by_xpath(".//*[@id='menubar-export']/a/span[1]/span[2]").click()
action.move_to_element(driver.find_element_by_xpath(".//*[@id='menubar-export']/a/span[1]/span[2]"))
driver.find_element_by_xpath(".//*[@id='ui-menu-0-1']").click()
1
Can you consider narrowing down to exact line are you facing the error? Do update with the manual steps you are trying to perform. ThanksDebanjanB

1 Answers

0
votes

Most likely the actual <select> element is not visible on the page and the select you see on the page is a pseudo-select element made for example of <div> or <li> elements.

This is now becoming more common, given that there are limited options to style native selects. As a result many frameworks 'overlay' them with better looking components and delegate the logic to the hidden underlying select via javascript.

The solution will be to find the actual visible elements and click them instead of the <select> or use driver.execute_script(...) to drive the widgets via javascript.