Python Selenium正在尝试导出文件

Python Selenium正在尝试导出文件,python,selenium,xpath,Python,Selenium,Xpath,我昨天偶然发现了Selenium,并能够成功登录到一个网站并导航到一个通常需要手动操作的页面。我试图复制xpath,但找不到元素。看起来是这样的: 我想导航到数据-->CSV格式并单击它 我对其进行了编辑,以包含inspect元素的顶部。这涉及到导出到PDF选项,请记住我想要的是CSV格式,而不是PDF格式 <document> <html lang="en" dir="ltr" style="visibility: visible;"> <head> &l

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

我想导航到数据-->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>

obips.history.create();
var dashboardCurrentStyle=“FusionFx”
obips.ResourceManager.seedResource({p:“common/privileges.xml”,v:{exprs:{“canAccessCatalogUI”:true,“canAccessCatalogSearchUI”:false,“canAccessHomePage”:true,“canAccessSimpleSearchField”:false,“canAccessAdvancedSearchLink”:false,“CanAccessPenMenu”: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,“仪表板详细信息”),“,”,{'Oracle':'olh/l_en/toc.htm','Oracle Publisher':'saw.dll?xmlpObjectTasks“+'&Action=help','Marketing':'olh/l_en/Marketing/mstoc.html');saw.getsessioninfo().portalPath='/shared/_portal/Dashboard Detail';
obidash.pageIdentifier='sfcjp24m8jpf8gbu';obidash.canSaveSelectionForMe=true;
未给出“导出”菜单标题和“数据”菜单项的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()

这是一个通过oracle运行的商业智能门户。它还需要用户名和密码等。我希望“Inspect Element”部分足够了。这应该是一个评论而不是一个答案。@KetanSethi:那么你应该发布一些真实的答案来获得这50个代表。这“很容易,因为我今天得到了100个代表”。@kevinguan好的,先生当然,等等,我不认为这是Python代码。OP正在使用Python运行selenium。好吧,如果你能显示完整的HTML代码或URL,那就更好了。但是如果你真的不能,你的HTML代码部分只有一个
a
标记,你想点击它吗?看起来你需要使用
ActionChain()
类及其相关方法。它将允许您执行可能需要执行的鼠标悬停类型操作。我尝试添加更多信息,希望能有所帮助。不幸的是,我对这方面完全陌生。我可以尝试一下。导出按钮的xpath有效。我可以看到它正确弹出。我只是无法从那里导航“/*[@id='popupMenuItem']/table/tbody/tr/td[2]”这是为所有菜单项提供的xpath。因此,我无法指定“数据”或“CSV格式”。这是导出按钮的xpath,但仍然有效:“./*[@id='d:dashboard~p:sfcjp24m8jpf8gbu~r:tom49amopk60jlinks']/tbody/tr/td[5]/a”
/*[@id='popupMenuItem']/可以尝试使用table/tbody/tr/td[text()='Data']
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()