使用selenium webdriver查找xpath / css

时间:2014-10-30 05:34:10

标签: css xpath

我找不到链接的xpath / css选择器:“选择参与者”在下面的网页中,然后我将遍历所有链接。

<div class="glossymenu">
                                                <a class="menuitem submenuheader" href="#" headerindex="0h"><span class="accordprefix"></span>Participant Management<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="0c" style="display: none;">
                                                    <ul>
                                                        <li><a id="ParticipantManagement" style="cursor:pointer" onclick="javascript:CheckPermission('ParticipantManagement','ParticipantManagement.aspx')">Select Participant</a></li>
                                                        <li><a id="DocumentApproval" style="cursor:pointer" onclick="javascript:CheckPermission('DocumentApproval','DocumentApproval.aspx')">Quick Document Approval</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="1h"><span class="accordprefix"></span>System Management<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="1c" style="display: none;">
                                                    <ul>
                                                        <li><a id="ctl00_CommonMaster" style="cursor:pointer" onclick="javascript:CheckPermission('CommonMaster','CommonMaster.aspx')">Common Master Tables</a></li>
                                                        <li><a id="SystemEventMaintenance" style="cursor:pointer" onclick="javascript:CheckPermission('SystemEventMaintenance','SystemEventMaintenance.aspx')">Event</a></li>
                                                        <li><a id="ImportCategoryMaster" style="cursor:pointer" onclick="javascript:CheckPermission('ImportCategoryMaster','ImportCategoryMaster.aspx')">Import Configuration
                                                            Type </a></li>
                                                        <li><a id="ColumnRuleMapper" style="cursor:pointer" onclick="javascript:CheckPermission('ColumnRuleMapper','ColumnRuleMapper.aspx')">Import Column Rule Mapper</a></li>

                                                        <li><a id="ctl00_SMTPDetailMaster" style="cursor:pointer" onclick="javascript:CheckPermission('SMTPDetailMaster','SMTPDetailMaster.aspx')">SMTP Detail</a></li>
                                                        <li><a id="ClientCodeMaster" style="cursor:pointer" onclick="javascript:CheckPermission('ClientCodeMaster','ClientCodeMaster.aspx')">Client Code Master</a></li>
                                                        <li><a id="ClientMaster" style="cursor:pointer" onclick="javascript:CheckPermission('ClientMaster','ClientMaster.aspx')">Client Management</a></li>
                                                        <li><a href="UserEntryMaster.aspx" id="ctl00_UserEntryMaster">User And Role
                                                            Management</a></li>

                                                        <li><a id="Scheduler" style="cursor:pointer" onclick="javascript:CheckPermission('Scheduler','Scheduler.aspx')">Schedule</a></li>
                                                        <li><a id="TransactionStatements" href="TransactionStatement.aspx">Transaction Statements</a></li>
                                                        <li><a id="AddCustomColumn" style="cursor:pointer" onclick="javascript:CheckPermission('AddCustomColumn','AddCustomColumn.aspx')">Manage Custom Field</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="2h"><span class="accordprefix"></span>Client/Case Configuration<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="2c" style="display: none;">
                                                    <ul>
                                                        <li><a id="ClientCaseMaster" style="cursor:pointer" onclick="javascript:CheckPermission('ClientCaseMaster','ClientCaseMaster.aspx')">Case Management</a></li>
                                                        <li><a id="RegionMapping" style="cursor:pointer" onclick="javascript:CheckPermission('RegionMapping','RegionMapping.aspx')">Region Mapping</a></li>
                                                        <li><a id="ClassificationMaintenance" style="cursor:pointer" onclick="javascript:CheckPermission('ClassificationMaintenance','ClassificationMaintenance.aspx')">Classification
                                                            Maintenance</a></li>
                                                        <li><a id="SubClassificationMaintenance" style="cursor:pointer" onclick="javascript:CheckPermission('SubClassificationMaintenance','SubClassificationMaintenance.aspx')">Sub
                                                            Classification Maintenance</a></li>
                                                        <li><a id="PlanYearMaintenance" style="cursor:pointer" onclick="javascript:CheckPermission('PlanYearMaintenance','PlanYearMaintenance.aspx')">Plan Year Maintenance</a></li>
                                                        <li><a id="CarrierCompare" href="CarrierCompare.aspx">Carrier Compare</a></li>
                                                        <li><a id="Theme" style="cursor:pointer" onclick="javascript:CheckPermission('Theme','Theme.aspx')">Configure Client Style</a></li>
                                                        <li><a id="EmployeeDeshboardTiles" style="cursor:pointer" onclick="javascript:CheckPermission('EmployeeDashboardTile','EmployeeDashboardTile.aspx')">Employee Dashboard
                                                            Tile Management</a></li>
                                                        <li><a id="RelationShipManagement" style="cursor:pointer" onclick="javascript:CheckPermission('RelationShipManagement','RelationShipManagement.aspx')">Dependent Relationship Management</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="3h"><span class="accordprefix"></span>Client Maintenance<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="3c" style="display: none;">
                                                    <ul>
                                                        <li><a id="TierCustomCodeMaster" style="cursor:pointer" onclick="javascript:CheckPermission('TierCustomCodeMaster','TierCustomCodeMaster.aspx')">Tier CustomCode Master</a></li>
                                                        <li><a id="BenefitSetup" style="cursor:pointer" onclick="javascript:CheckPermission('BenefitSetup','BenefitSetup.aspx')">Benefits</a></li>
                                                        <li><a id="PlanSetup" style="cursor:pointer" onclick="javascript:CheckPermission('PlanSetup','PlanSetup.aspx')">Plans</a></li>
                                                        <li><a id="Events" style="cursor:pointer" onclick="javascript:CheckPermission('ClientEvent','ClientEventMaintenance.aspx')">Events</a></li>
                                                        <li><a id="EventWebDirections" style="cursor:pointer" onclick="javascript:CheckPermission('EventWebDirection','EventWebDirection.aspx')">Manage Event Web Directions</a></li>
                                                        <li id="ctl00_liTriggerEvent" style="display:none;"><a id="TriggerEvent" href="TriggerEvent.aspx&gt;
                                                            Trigger An Event&lt;/a&gt;&lt;/li&gt;
                                                        &lt;li&gt;&lt;a id=" deletedependency"="" style="cursor:pointer" onclick="javascript:CheckPermission('DeleteDependency','DeleteDependency.aspx')">Delete Dependency</a></li>
                                                        <li><a id="AdminStatements" style="cursor:pointer" onclick="javascript:CheckPermission('AdminStatements','AdminStatements.aspx')">Admin Statements</a></li>
                                                        <li><a id="FormLibrary" style="cursor:pointer" onclick="javascript:CheckPermission('FormsLibrary','FormsLibrary.aspx')">Forms Library</a></li>
                                                        <li><a id="UpdateEventDate" style="cursor:pointer; display:none" onclick="javascript:CheckPermission('UpdateEventDate','UpdateEventDate.aspx')">Update Event Date</a></li>


                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="4h"><span class="accordprefix"></span>Client Import Administration<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="4c" style="display: none;">
                                                    <ul>
                                                        <li><a id="TriadMapping" style="cursor:pointer" onclick="javascript:CheckPermission('TriadMapping','TriadMapping.aspx')">Client Code Mapper</a></li>
                                                        <li><a id="ImportTemplate" style="cursor:pointer" onclick="javascript:CheckPermission('ImportTemplate','ImportTemplate.aspx')">Import Template</a></li>
                                                        <li><a id="ImportReport" href="ImportReport.aspx">Import History</a></li>
                                                        <li><a id="VerifyEmployeeDetails" href="VerifyEmployeeDetails.aspx">Review/Approve Client
                                                            Import Files</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="5h"><span class="accordprefix"></span>Email Administration<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="5c" style="display: none;">
                                                    <ul>
                                                        <li><a id="EmailTemplate" style="cursor:pointer" onclick="javascript:CheckPermission('EmailTemplate','EmailTemplate.aspx')">Email Template</a></li>
                                                        <li><a id="EmailConfiguration" style="cursor:pointer" onclick="javascript:CheckPermission('EmailConfiguration','EmailConfiguration.aspx')">Email Configuration</a></li>
                                                        <li><a id="EmailQueue" style="cursor:pointer" onclick="javascript:CheckPermission('EmailQueue','EmailQueue.aspx')">Email Queue</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="6h"><span class="accordprefix"></span>Content Management System<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="6c" style="display: none;">
                                                    <ul>
                                                        <li><a id="CMSLeftMenu" style="cursor:pointer" onclick="javascript:CheckPermission('CMSLeftMenu','CMSLeftMenu.aspx')">Left Menu Configuration</a></li>
                                                        <li><a id="CMSImage" style="cursor:pointer" onclick="javascript:CheckPermission('CMSTile','CMSImage.aspx')">Tile Configuration</a></li>
                                                        <li><a id="CMSContent" style="cursor:pointer" onclick="javascript:CheckPermission('CMSContent','CMSContent.aspx')">Content Configuration</a></li>
                                                        <li><a id="CMSRightPanel" style="cursor:pointer" onclick="javascript:CheckPermission('CMSRightPanel','CMSRightPanel.aspx')">Page Configuration</a></li>
                                                        <li><a id="CMSAlertsMaster" style="cursor:pointer" onclick="javascript:CheckPermission('CMSAlert','CMSAlertsMaster.aspx')">CMS Alert Template</a></li>
                                                        <li><a id="PrivacyStatementMaster" style="cursor:pointer" onclick="javascript:CheckPermission('PrivacyStatementMaster','PrivacyStatementMaster.aspx')">Privacy Statement</a></li>
                                                        <li><a id="AppearanceOrder" style="cursor:pointer" onclick="javascript:CheckPermission('AppearanceOrder','AppearanceOrder.aspx')">Appearance Order</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="7h"><span class="accordprefix"></span>Document Management System<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="7c" style="display: none;">
                                                    <ul>
                                                        <li><a id="DMSCategory" style="cursor:pointer" onclick="javascript:CheckPermission('DMSCategory','DMSCategory.aspx')">Document Category</a></li>
                                                        <li><a id="DMSAddDocument" style="cursor:pointer" onclick="javascript:CheckPermission('DMSAddDocument','DMSAddDocument.aspx')">Document Library</a></li>

                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="8h"><span class="accordprefix"></span>OE Management System<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="8c" style="display: none;">
                                                    <ul>
                                                        <li><a id="OEManagementSystem" style="cursor:pointer" onclick="javascript:CheckPermission('OEEventCreation','OEEventCreation.aspx')">Make OE Events</a></li>
                                                        <li><a id="ImportExportPayCalendar" style="cursor:pointer" onclick="javascript:CheckPermission('ImportExportPayCalendar','ImportExportPayCalendar.aspx')">Import/Export
                                                            Pay Calendar</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="9h"><span class="accordprefix"></span>Logs<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="9c" style="display: none;">
                                                    <ul>
                                                        <li><a id="LoginTrack" href="LoginTrack.aspx?IsFromlink=Yes">Login History</a></li>
                                                        <li><a id="ErrorLog" href="ErrorLog.aspx">Error Log</a></li>
                                                        <li><a id="ErrorLogWatcher" href="ErrorLogWatcher.aspx">Application Exceptions</a></li>
                                                    </ul>
                                                </div>
                                                <a class="menuitem submenuheader" href="#" headerindex="10h"><span class="accordprefix"></span>Outbound Files<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="10c" style="display: none;">
                                                    <ul>
                                                        <li><a id="ReviewOutboundFiles" href="ReviewOutboundFiles.aspx">Review Outbound Files</a></li>
                                                    </ul>
                                                </div>
                                                <a href="#" id="ctl00_Security" class="menuitem submenuheader" headerindex="11h"><span class="accordprefix"></span>Security<span class="accordsuffix"><img src="../images/plus-ac.png" class="statusicon"></span></a>
                                                <div class="submenu" contentindex="11c" style="display: none;">
                                                    <ul>
                                                        <li><a id="ctl00_ClientCase" style="cursor:pointer" onclick="javascript:CheckPermission('ClientCase','ClientCase.aspx')">Client/Case Permission</a></li>
                                                        <li><a id="UserPageEntry" style="cursor:pointer" onclick="javascript:CheckPermission('UserPageEntry','UserPageEntry.aspx')">Page Master</a></li>
                                                        <li><a id="UserPermission" href="UserPagePermission.aspx">Page Rights</a></li>
                                                        <li><a id="ParticipantView" href="ParticipantView.aspx">Participant Page View</a></li>
                                                    </ul>
                                                </div>
                                            </div> //

List Links = Driver.findElements(By.xpath(“// div [contains(@ class ='glossymenu')] // a”));         Iterator iter = Links.iterator();    // System.out.println(“CLASS Elements size”+ we.getText());             while(iter.hasNext()){

        WebElement we = iter.next();
        //System.out.println(" CLASS  Elements size " + we.getText());
        if (we.getText().contains("Select Participant")) {
            we.click();
           break;

        }

       }    

// System.out.println(“CLASS Elements size”+ we.getText());

2 个答案:

答案 0 :(得分:0)

链接的xpath / css选择器:&#34;选择参与者&#34; :  //div[contains(@class='glossymenu')]//a[text()='Select Participant']

答案 1 :(得分:0)

上述答案中的小修正

应该是这样的: -

// div [@class =&#39; glossymenu&#39;] // a [text()=&#39;选择参与者&#39;] 要么 // div [包含(@class,&#39; glossymenu&#39;)] //一个[text()=&#39;选择参与者&#39;]