In Selenium how to select an option if the span class and div class are not unique -
we have tabs called community, resources , support have same section class div class , span class attributes seen in html code below. how "select" or choose 1 of tabs , traverse down path links.
<section class="s-fn-item"> <div class="s-fn-wrapper-item"> <h5 class="s-fn-title-item"> <span class="s-fn-item-link">community</span> </h5> <div class="s-fn-wrapper-sub-menu bg-base bg-shadow-down-medium fn- offscreen" style="display: block; height: 245px;"> <ul class="s-fn-sub-menu-item"> <li class="s-fn-promo-sub-menu-item"><a href="here link" class="s-fn-sub-item-link" title="qa community home">qa community home</a> </li> <li class="s-fn-promo-sub-menu-item"><a href="/community" class="s-fn-sub-item-link" title="community home">community home</a> </li> <li class="s-fn-promo-sub-menu-item"><a href="/community/events-webinars" class="s-fn-sub-item-link" title="community events">community events</a> </li> </ul> </div> </div> </section> <section class="s-fn-item"> <div class="s-fn-wrapper-item"> <h5 class="s-fn-title-item"> <span class="s-fn-item-link">resources</span> </h5> <div class="s-fn-wrapper-sub-menu bg-base bg-shadow-down-medium fn-offscreen" style="display: block; height: 227px;"> <ul class="s-fn-sub-menu-item"> <li class="s-fn-promo-sub-menu-item"><a href="/support/articles-and-how-tos" class="s-fn-sub-item-link" title="articles , how-tos">articles , how-tos</a> </li> <li class="s-fn-promo-sub-menu-item"><a href=”here link” class="s-fn-sub-item-link" title="blog">blog</a> </li>
storymakers support support home contact installation , licensing
i agree @user1433852 using relative xpaths make life easier.. :) . have formulated relative xpaths below find menu community/resources , xpath sub-menu item under them:
//span[.='community']
select 'span' element exact inner html or text 'community'.
//span[.='community']/ancestor::div[@class='s-fn-wrapper-item']//a[@title='qa community home']
select 'a' element title 'qa community home' under div element class 's-fn-wrapper-item' ancestor of the 'span' element exact inner html or text 'community'.similarly,
//span[.='resources']
select 'span' element exact inner html or text 'resources'.//span[.='resources']/ancestor::div[@class='s-fn-wrapper-item']//a[@title='articles , how-tos']
select 'a' element title 'articles , how-tos' under div element class 's-fn-wrapper-item' ancestor of 'span' element exact inner html or text 'resources'.
so, in both cases above using the primary items, i.e., community , resources submenu items, are, qa community home , articles , how-tos, respectively.
Comments
Post a Comment