The objective is to select either one of the four sub menus (i.e., Subject area, Title, Publisher, ISSN
) as depicted in the picture below from the Scopus website that accessible via the link: https://www.scopus.com/sources?zone=TopNavBar&origin=NO%20ORIGIN%20DEFINED
The html snippet for the search result comb drop menu
by the class name ui-menu ui-corner-bottom ui-widget ui-widget-content
is
<ul aria-hidden="false" aria-labelledby="srcResultComboDrp-button" id="srcResultComboDrp-menu" role="listbox" tabindex="0" class="ui-menu ui-corner-bottom ui-widget ui-widget-content" aria-activedescendant="ui-id-1" aria-disabled="false" style="width: 251px;">
<li class="ui-menu-item">
<div id="ui-id-1" tabindex="-1" role="option" class="ui-menu-item-wrapper ui-state-active">Subject area</div>
</li>
<li class="ui-menu-item">
<div id="ui-id-2" tabindex="-1" role="option" class="ui-menu-item-wrapper">Title</div>
</li>
<li class="ui-menu-item">
<div id="ui-id-3" tabindex="-1" role="option" class="ui-menu-item-wrapper">Publisher</div>
</li>
<li class="ui-menu-item">
<div id="ui-id-4" tabindex="-1" role="option" class="ui-menu-item-wrapper">ISSN</div>
</li>
</ul>
Say we are interested to select the sub-menu Title
, then the objective can be achieved as suggested by OP1, by the following lines;
from selenium import webdriver
driver = webdriver.Chrome(r"C:Browsers\chromedriver.exe")
url = 'https://www.scopus.com/sources?zone=TopNavBar&origin=NO%20ORIGIN%20DEFINED'
driver.get(url)
driver.find_element_by_xpath('//*[@id="ui-id-2"]').click()
However, the compiler return the following error;
Unable to locate element: {"method":"xpath","selector":"//*[@id="ui-id-2"]"}
Similarly, using the following line as suggested by OP2
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome(r"C:Browsers\chromedriver.exe")
url = 'https://www.scopus.com/sources?zone=TopNavBar&origin=NO%20ORIGIN%20DEFINED'
driver.get(url)
my_select = Select(driver.find_element_by_id('srcResultComboDrp-menu'))
my_select.select_by_visible_text('Title')
Return the following error:
selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on <select> elements, not on <ul>
May I know where did I do wrong? Appreciate for any help