Why span element text is not coming here attaching the main div content here I am trying to pinpoint My work here but I am getting No element found what's wrong here how can I store this Myvalue element so that i can give click command on it , pardon my English,also if any better alternatives approach available please suggest
main_div = driver.find_elements(By.CLASS_NAME, "sub-menu")
# print(main_div)
for i in main_div:
for span in i.find_element(By.XPATH,'.//span[@class = "leaf_line_item"]'):
print(span)
Html code below fetched from main_div
<li >Home</li>
<li
onclick="executeNavigationAction('My Inbox','plm/workspace/myWorkspace.jsp?activeTab=My Inbox','false');"><span
>My Inbox</span></li>
<li
onclick="executeNavigationAction('My Work','plm/workspace/myWorkspace.jsp?activeTab=My Work','false');"><span
>My Work</span></li>
<li
onclick="executeNavigationAction('My Timesheet New','plm/workspace/myWorkspace.jsp?activeTab=My Timesheet New','false');">
<span >My Timesheet</span></li>
<li
onclick="executeNavigationAction('My Calendar','plm/workspace/myWorkspace.jsp?activeTab=My Calendar','false');">
<span >My Calendar</span></li>
<li
onclick="executeNavigationAction('My Attendance','plm/workspace/myWorkspace.jsp?activeTab=My Attendance','false');">
<span >My Swipe Hours</span></li>
<li
onclick="executeNavigationAction('My Meetings','plm/workspace/myWorkspace.jsp?activeTab=My Meetings','false');">
<span >My Meetings</span></li>
<li >My Details</li>
<li ><span style="cursor: pointer; cursor: hand;"
onclick="executeNavigationAction('detailsNodeIdPM','ngtb/resource/resourceContainer.jsp?userId=6fih1mq0be20001000030ag19l&module=PGM','false');">My
Profile</span>
<ul style="display: none;top:-45px">
<li >My Profile</li>
<li
onclick="executeNavigationAction('delegationNodeIdPM','ngtb/delegation/delegationContainer.jsp?module=PGM','false');">
<span >Delegation</span></li>
</ul>
</li>
<li ><span style="cursor: pointer; cursor: hand;"
onclick="executeNavigationAction('settingsNodeIdPM','plm/user/userPreferences.jsp?callingMode=leftTree&userId=6fih1mq0be20001000030ag19l&module=PGM','false');">My
Settings</span>
<ul style="display: none;top:-45px">
<li >My Settings</li>
<li
onclick="executeNavigationAction('updateSettingsNodeIdPM','ngtb/resource/userSettingNewUI.jsp?userId=6fih1mq0be20001000030ag19l&Action=Edit&objectType=UserSetting&callingMode=leftTree&module=PGM','false');">
<span >Update Settings</span></li>
</ul>
</li>
<li >My Resources</li>
<li
onclick="executeNavigationAction('myResourceWorkNodeIdPM','ngtb/resource/myTeamContainerNew.jsp?objectType=ResourcesDetails&selectedTabId=PLM_RDT_RESOURCE_DETAILS&classId=factory_default_cl&module=PLM&isOldUI=true&module=PGM','false');">
<span >My Team Details</span></li>
<li >Deliverable Reviews</li>
<li
onclick="javascript:fnOpenPopUp('plm/search/query.jsp?pageName=Advanced Search&isNew=true&searchCurrentTab=Advanced Search&pmSearchPopUpPage&subModuleName=TechnicalReview&module=PLM&classId=cl_tech_review&treeNode=cl_tech_review');">
<span >Advanced Search</span></li>
<li
onclick="executeNavigationAction('DashboardNodeIdFotMyTR','plm/search/query.jsp?pageName=Views&isNew=true&searchCurrentTab=My Dashboard&&subModuleName=TechnicalReview&module=PLM&module=PGM','false');">
<span >Dashboard</span></li>
<li >Knowledge Management</li>
<li
onclick="executeNavigationAction('kbTemplateIdPM','kb/kbTemplateManagement.jsp?objectType=kbTemplate&module=PGM','false');">
<span >Templates</span></li>
<li
onclick="executeNavigationAction('kbAddNodeIdPM','taxonomy.do?action=AddNewKBUI&objectType=Document&addDocFrom=HDDToKB&callingMode=LeftTree&IS_WIZARD_ACTION=true&module=PGM','false');">
<span >Add Knowledge</span></li>
<li
onclick="executeNavigationAction('kbSignOffNodeIdPDM','ngtb/KB/views/knowledgeFilterList.jsp?objectType=KbSignOamp;module=PGM','false');">
<span >Knowledge</span></li>
<li
onclick="executeNavigationAction('kbRequestNodeIdPM','kb/kbRequestTab.jsp?objectType=KbRequestAcceptRejectUI&module=PGM','false');">
<span >My Requests</span></li>
<li
onclick="executeNavigationAction('kbSearchNodeIdPM','ngtb/knowledgeBase/knowledgeBaseContainer.jsp?objectType=simpleSearch&pageAction=searchMainPage&start=1&isFromSearchNode=true&module=PGM','false');">
<span >Search</span></li>
<li
onclick="javascript:fnOpenPopUp('/search/query.jsp?pageName=Advanced Search&isNew=true&searchCurrentTab=Advanced Search&pmSearchPopUpPage&module=KB');">
<span >Advanced</span></li>
<li
onclick="executeNavigationAction('boardNodeIdPM','plm/search/query.jsp?pageName=Views&isNew=true&searchCurrentTab=My Dashboard&module=KB&module=PGM','false');">
<span >Dashboards</span></li>
<li
onclick="executeNavigationAction('knowledgeBaseReportsNodeIdPM','plm/report/knowledgeBaseReports.jsp?module=PGM','false');">
<span >Reports</span></li>
<li
onclick="executeNavigationAction('kbConfigureAlertNodeIdPM','plm/event/ModuleEventsList.jsp?module=KB&module=PGM','false');">
<span >Alerts </span></li>
<li >Management</li>
<li ><span style="cursor: pointer; cursor: hand;"
onclick="executeNavigationAction('extProjectRequestNodeId','plm/projectdata/projectDataFilterTabs.jsp?objectType=External Project List Master&selectedTabId=EXT_PROJ_LIST_TAB_DETID&classId=cl_external_project_data&module=PLM&module=PGM','false');">EKA
Projects</span>
<ul style="display: none;top:-45px">
<li >EKA Projects</li>
<li
onclick="executeNavigationAction('extProjListPM','plm/projectdata/projectDataFilterTabs.jsp?objectType=External Project List Master&selectedTabId=EXT_PROJ_LIST_TAB_DETID&classId=cl_external_project_data&module=PLM&module=PGM','false');">
<span >List</span></li>
<li
onclick="javascript:fnOpenPopUp('plm/search/query.jsp?pageName=Advanced Search&isNew=true&searchCurrentTab=Advanced Search&pmSearchPopUpPage=&module=PGM&rootSubType=External&classId=cl_external_project_data&subModuleName=ProjectData');">
<span >Advanced Search</span></li>
<li
onclick="executeNavigationAction('extProjDashIdPM','plm/search/query.jsp?pageName=Views&isNew=true&searchCurrentTab=My Dashboard&subModuleName=ProjectData&classId=cl_external_project_data&rootSubType=External&module=PGM','false');">
<span >Dashboard</span></li>
</ul>
</li>
CodePudding user response:
You can try this using xpath
main_div = driver.find_elements(By.CLASS_NAME, "sub-menu")
# print(main_div)
for i in main_div:
for span in i.find_element(By.XPATH,'.//span[@class = "leaf_line_item"]'):
span.find_element(By.XPATH,'//li[@]//span[@]')
CodePudding user response:
the problem here is the xpath
(By.XPATH,'.//span[@class = "leaf_line_item"]')
delete the dot at the beginning of the path, it must start with a double backslash