我有以下Xpath
"//*[@id="idDownloadDataMenuo:portalgo~r:report"]/table/tbody/tr[1]/td[1]/a[1]/table/tbody/tr/td[1]/img"
和以下CSS
"#idDownloadDataMenuo\3a portalgo\7e r\3a report > table > tbody > tr:nth-child(1) > td.shadowMenuCell > a:nth-child(1)"
当我尝试单击该路径后,发现抛出以下错误。
也尝试了很多组合 “消息:没有这样的元素:无法找到元素:{” method“:” xpath“,” selector“:” // * [@ id ='idDownloadDataMenuo:portalgo〜r:report'] // td [ text()='CSV格式']“}”
相同的Xpath在控制台中也起作用,下面是输出。
''' $x("//*[@id='idDownloadDataMenuo:portalgo~r:report']//td[text()='CSV Format']")
'''
下面是我的代码
browser.execute_script('''window.open("https://XXXXXXXXX.XXXXXXXX=YYYYYYYYYYYY%20report","_blank");''')
time.sleep(40)
#findpath = "//td[text()='CSV Format'] or //td[contains(text(),'report')]"
findpath = "//*[@id='idDownloadDataMenuo:portalgo~r:report']//td[text()='CSV Format']"
browser.find_element_by_xpath(findpath).click()
我的完整HTML标记对于CSV部件,类似地,PDF,EXCEL也具有相同的类。
<tr><td rowspan="2" colspan="2" class="shadowMenuCell"><a class="NQWMenuItem NQWMenuItemWIconMixin" name="SectionElements" href="javascript:void(null);" onclick="NQWClearActiveMenu();return Download('saw.dll?Go&ViewID=o%3aportalgo%7er%3areport&Action=Download&SearchID=fk3n3gl49dtd24splb64lli3lm&Style=blafp&ViewState=ok0jv8tnkb2ckftn5ucih1hnnq&ItemName=Anil%20-%20Steering%20vs%20Costs%20tracker%20report&path=%2fusers%2fj000432%2fAnil%20-%20Steering%20vs%20Costs%20tracker%20report&Format=csv&Extension=.csv');"><table class="MenuItemTable" cellspacing="0" cellpadding="0"><tr><td class="MenuItemIconCell"><img alt="" src="res/sk_blafp/catalog/exporttocsv_ena.png"></td><td class="MenuItemTextCell">CSV Format</td></tr></table></a><a class="NQWMenuItem NQWMenuItemWIconMixin" name="SectionElements" href="javascript:void(null);" onclick="NQWClearActiveMenu();return Download('saw.dll?Go&ViewID=o%3aportalgo%7er%3areport&Action=Download&SearchID=fk3n3gl49dtd24splb64lli3lm&Style=blafp&ViewState=ok0jv8tnkb2ckftn5ucih1hnnq&ItemName=Anil%20-%20Steering%20vs%20Costs%20tracker%20report&path=%2fusers%2fj000432%2fAnil%20-%20Steering%20vs%20Costs%20tracker%20report&Format=txt&Extension=.csv');"><table class="MenuItemTable" cellspacing="0" cellpadding="0"><tr><td class="MenuItemIconCell"><img alt="" src="res/sk_blafp/catalog/exporttocsv_ena.png"></td><td class="MenuItemTextCell">Tab delimited Format</td></tr></table></a><a class="NQWMenuItem NQWMenuItemWIconMixin" name="SectionElements" href="javascript:void(null);" onclick="NQWClearActiveMenu();return Download('saw.dll?Go&ViewID=o%3aportalgo%7er%3areport&Action=Download&SearchID=fk3n3gl49dtd24splb64lli3lm&Style=blafp&ViewState=ok0jv8tnkb2ckftn5ucih1hnnq&ItemName=Anil%20-%20Steering%20vs%20Costs%20tracker%20report&path=%2fusers%2fj000432%2fAnil%20-%20Steering%20vs%20Costs%20tracker%20report&Format=xml&Extension=.txt');"><table class="MenuItemTable" cellspacing="0" cellpadding="0"><tr><td class="MenuItemIconCell"><img alt="" src="res/sk_blafp/catalog/exporttoxml_ena.png"></td><td class="MenuItemTextCell">XML Format</td></tr></table></a>
FOR ... MHT
<tr><td class="shadowRight"> </td></tr><tr><td class="shadowOffsetCellBottom"></td><td class="shadowBottom"> </td><td class="shadowCorner"></td></tr> </table></div><a class="NQWMenuItem NQWMenuItemWIconMixin" name="SectionElements" href="javascript:void(null);" onclick="NQWClearActiveMenu();Download('saw.dll?Go&ViewID=o%3aportalgo%7er%3areport&Action=Download&SearchID=fk3n3gl49dtd24splb64lli3lm&Style=blafp&ViewState=ok0jv8tnkb2ckftn5ucih1hnnq&ItemName=Anil%20-%20Steering%20vs%20Costs%20tracker%20report&path=%2fusers%2fj000432%2fAnil%20-%20Steering%20vs%20Costs%20tracker%20report&Format=mht'); return false"><table class="MenuItemTable" cellspacing="0" cellpadding="0"><tr><td class="MenuItemIconCell"><img alt="" src="res/sk_blafp/catalog/exporttomhtml_ena.png"></td><td class="MenuItemTextCell">Web Archive (.mht)</td></tr></table></a><a class="NQWMenuItem NQWMenuItemWIconMixin" href="javascript:void(null)" onclick="return false;" onmouseover="saw.menuItemMouseOver(event,'idDownloadDataMenuo:portalgo~r:report');"><table class="MenuItemTable" cellspacing="0" cellpadding="0"><tr><td class="MenuItemIconCell"><img alt="" src="res/sk_blafp/catalog/exporttocsv_ena.png"></td><td class="MenuItemTextCell">Data</td><td class="MenuItemRightArrowCell"><img src="res/sk_blafp/common/menurtarrow.gif" title="Download columnar data" alt="Download columnar data"></td></tr></table></a></td>
提前感谢...