Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

angularjs - Is there any way to getting selenium to click on below link (ng-click) using python?

I have the following html with multiple links that use similar class and id and I want to click on the link which has 'toh' with python selenium.

<div Class="ibox-content">
  <ul Class="sortable-list policy-list">
    <li Class="success-element" id ng-click=
    "showReport($event,policy['toh'].policyCode,policy['toh']
    .policyName,policy['toh'].policyCurrencyCode);" style=
    "background-color: rgba(37, 128, 219, 0.2);">
                                    TOH
                                 </li> 
    <li Class="success-element" id ng-click=
    "showReport($event,policy['cuso'].policyCode,policy['cuso']
    .policyName,policy['cuso'].policyCurrencyCode);" style=
    "background-color: rgba(37, 128, 219, 0.2);">
                                    CUSO
                                 </li>                             

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can make use of xpath

//div[@class='ibox-content']//ul//li[1]

This works as shown in the image below

enter image description here

In your python

driver.find_element_by_xpath("//div[@class='ibox-content']//ul//li[1]");

Or use below CSS selector

.ibox-content ul li

Works as shown in the image below enter image description here

In your python

driver.find_element_by_css_selector(".ibox-content ul li");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...