单击使用Python和Selenium的打开的嵌套无序HTML列表(下拉菜单)

时间:2019-05-17 23:05:46

标签: python-3.x selenium-webdriver selenium-chromedriver

我想单击打开的导航栏元素(“住宅分离”),显示在这里:enter image description here

以下是该元素后面的HTML:

<div id="app_banner_menu">
   <ul class="AspNet-Menu">
      <li><a data-bind="" url="/ParagonLS/Home/Page.mvc" tabDescription="Home" subTabDescription="" subTabMaxAllowed="0" targetEx="" rel="" subTabGroup="false" subTabGroupAdd="false" subTabStartIndex="" subTabGroupClose="false" fullWindow="False" hideAddressBar="False"><span id="home-nav" class="MenuIcons homeButton"></span></a></li>
      <li>
         <span id="search-nav" class="MenuIcons searchButton"></span>
         <div>
            <ul>
               <li>
                  Search By Class
                  <ul>
                     <li><a data-bind="" url="/ParagonLS/Search/Property.mvc/Index/1" tabDescription="Residential Detached" subTabDescription="Criteria" subTabMaxAllowed="3" targetEx="" rel="" class=" SearchByClass1 " subTabGroup="true" subTabGroupAdd="true" subTabStartIndex="0" subTabGroupClose="true" fullWindow="False" hideAddressBar="False">Residential Detached</a></li>
                     <li><a data-bind="" url="/ParagonLS/Search/Property.mvc/Index/2" tabDescription="Residential Attached" subTabDescription="Criteria" subTabMaxAllowed="3" targetEx="" rel="" class=" SearchByClass2 " subTabGroup="true" subTabGroupAdd="true" subTabStartIndex="0" subTabGroupClose="true" fullWindow="False" hideAddressBar="False">Residential Attached</a></li>

这是我为实现相同目的而编写的代码,但是它不起作用。

resedential_detached_class = browser.find_element_by_xpath("//div[contains(text(),'Residential Detached')]").click()

如何仅选择该元素并单击打开它?它将带我到一个新页面。

1 个答案:

答案 0 :(得分:0)

您尝试过这个硒标签吗?

resedential_detached_class = browser.find_element_by_link_text('Residential Detached')。click()