html - clicking on a link with the same href value using selenium python -


i have html code has 2 links both links have same href value, onclick , text different. wasn't sure how access second link. tried using driver.find_element_by_link_text('text'), no such element found error.

<div id="member">     <"a href="#" onclick="add_member("abc"); return false;">run abc<"/a>      <br>     <"a href="#" onclick="add_member("def"); return false;">run def<"/a> </div> 

there multiple options desired link.

one option use find_element_by_xpath() , check onclick attribute value:

link = driver.find_element_by_xpath('//div[@id="member"]/a[contains(@onclick, "add_member(\"def\")")]') link.click() 

another 1 find both links , desired 1 index:

div = driver.find_element_by_id('member') links = div.find_elements_by_tag_name('a') links[1].click() 

which option choose depends on whole html content. hope @ least 1 of 2 suggested solutions solves issue.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -