Python Selenium尝试导出fi

2024-10-01 15:42:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我昨天偶然发现了Selenium,并且能够成功地登录到一个网站并导航到一个我通常需要手动完成的页面。我试图复制xpath,但找不到元素。看起来像这样:

enter image description here 我想导航到Data-->CSV格式并单击它。在

我编辑了它以包含inspect元素的顶部。这是导出到PDF选项,请记住我想要CSV格式,而不是PDF。在

<document>
<html lang="en" dir="ltr" style="visibility: visible;">
<head>
<body class="PortalBody HTMLBody" style="">
<div class="HeaderContainer">
<script type="text/javascript">obips.history.create();</script>
<form style="position: absolute; top: -1000px; display:none;">
<script>var dashboardCurrentStyle = "FusionFx" </script>
<div id="idEmbedFrameDiv" style="" src="saw.dll?ReloadDashboard&InFrameset=false&Page=Dashboard%20Insight&Embed=true&PortalPath=%2fshared%20-%20DW%2f_portal%%20Dashboard%20Detail&Caller=Dashboard&ViewState=01qglnht7bjvn3nf9qrofvafjm"/>
<script type="text/javascript">obips.ResourceManager.seedResource({p:"common/privileges.xml",v:{exprs:{"canAccessCatalogUI":true,"canAccessCatalogSearchUI":false,"canAccessHomePage":true,"canAccessSimpleSearchField":false,"canAccessAdvancedSearchLink":false,"canAccessOpenMenu":true,"canAccessNewMenu":true,"canAccessHelpMenu":true,"canAccessDashboardsMenu":true,"canAccessFavoritesMenu":true,"canAccessMyAccountLink":true,"canAccessCustomLinks":false,"enableClientStorage":true,"enableSessionStorage":true,"enableLocalStorage":true,"canReloadMetadata":false,"canOpenMetadataDict":false}}});saw.header.alertsNode = ""; saw.header.renderHeader(null, 'Dashboard Detail', '', '', {'Oracle': 'olh/l_en/toc.htm', 'Oracle Publisher': "saw.dll?xmlpObjectTasks" + '&Action=help', 'Marketing': 'olh/l_en/marketing/mstoc.html' });saw.getSessionInfos().portalPath='/shared/_portal/Dashboard Detail';</script>
<script type="text/javascript">obidash.pageIdentifier = 'sfcjp24m8jpf8gbu';obidash.canSaveSelectionForMe = true;</script>
<div id="idPersonalizationMenu" class="NQWMenu" sdir="right" menuinit="" href="javascript:void(null)" onmouseout="NQWMenuMouseOut(event)" onmouseover="NQWMenuMouseOver(event)">
<div id="idDashboardPrintDisplayLayoutMenu" class="NQWMenu" sdir="left" submenuinit="" href="javascript:void(null)" onmouseout="NQWMenuMouseOut(event)" onmouseover="NQWMenuMouseOver(event)">
<div id="idDashboardPrintManageLayoutMenu" class="NQWMenu" sdir="left" submenuinit="" href="javascript:void(null)" onmouseout="NQWMenuMouseOut(event)" onmouseover="NQWMenuMouseOver(event)">
<div id="idDashboardExportToExcelMenu" class="NQWMenu" sdir="left" submenuinit="" href="javascript:void(null)" onmouseout="NQWMenuMouseOut(event)" onmouseover="NQWMenuMouseOver(event)">
<div id="idSavedSelectionsMenu" class="NQWMenu" sdir="left" submenuinit="PersonalizationEditor.getSavedSelectionsMenu" href="javascript:void(null)" onmouseout="NQWMenuMouseOut(event)" onmouseover="NQWMenuMouseOver(event)">
<script src="res/b_mozilla/common/componentheader.js" type="text/javascript"/>
<span id="sawruler" style="display:none;visibility:hidden;white-space:nowrap;"/>
<div class="ComponentHeader ">
<iframe id="idEmbed" style="visibility: hidden; width: 0px; height: 0px; position: absolute; top: 0px;" src="res/empty.htm" name="idEmbed" title="idEmbed"/>
<div id="idDownloadLinksMenud:dashboard~p:sfcjp24m8jpf8gbu~r:tom49amoppk60jjc" class="NQWMenu" onmouseover="NQWMenuMouseOver(event)" style="visibility: visible; display: block; position: absolute; top: 422px; left: 820px;" binit="true" role="menu" aria-activedescendant="popupMenuItem">
<table class="menuShadowWrapper" cellspacing="0">
<tbody>
<tr>
<td class="shadowMenuCell" colspan="2" rowspan="2">
<a id="popupMenuItem" class="NQWMenuItem NQWMenuItemWIconMixin" onclick="NQWClearActiveMenu();Download('saw.dll?Go&ViewID=d%3adashboard%7ep%3asfcjp24m8jpf8gbu%7er%3atom49amoppk60jjc&Action=Download&SearchID=c7gl7pgfjfdkhekcg09p3p8guq&Style=FusionFx&PortalPath=%2fshared%20-%20DW%2f_portal%20Dashboard%20Detail&Page=Dashboard%20Insight&ViewState=5cb5o5dpdpsh5id2japa3i0rvu&ItemName=Report%20Data&path=%2fshared%20-%20DW%20Dashboard%20New%20Report%20Data&Format=pdf&Attach=1'); return false" href="javascript:void(null);" name="SectionElements" style="width: 119px;" tabindex="0" role="menuitem" aria-label="PDF">
<table class="MenuItemTable" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="MenuItemIconCell">
<td class="MenuItemTextCell">PDF</td>
</tr>
</tbody>
</table>
</a>

Tags: diveventidfalsetruestylescriptjavascript
2条回答

没有给出“导出”菜单标题和“数据”菜单项的HTML。因此为他们做了假设。在

menu = driver.find_element_by_xpath('//table[@id="menu"]//td[text()="Export"]')
menuItem = driver.find_element_by_xpath('//table[@id="menu"]//td[text()="Data"]')
subMenuItem = driver.find_element_by_xpath('//table[@id="MenuItemTable"]//td[text()="CSV Format"]')

actions = ActionChains(driver)
actions.move_to_element(menu)
actions.move_to_element(menuItem)
actions.move_to_element(subMenuItem)
actions.click(subMenuItem)
actions.perform()
Actions a =new Actions(driver);
a.moveToElement(xpath of Export).moveToElement(xpath of Data).moveToElement(xpath of CSV Format).click().perform();

相关问题 更多 >

    热门问题