Python splinter(Selenium)问题单击带有Javascrip的菜单链接

2024-09-28 05:42:46 发布

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

我试着点击一个有碎片的框架的链接。当我尝试使用id、name、text和xpath时,它表示元素不存在。我试图得到所有的元素,但它也说找不到。在

import splinter

executable_path = {'executable_path':'C:\\code\\chromedriver-2.29\\chromedriver'}
web1 = splinter.Browser('chrome', **executable_path)

url = ""
ipAddr = '192.168.168.168'
web1.visit('https://' + ipAddr + '/' + url)

with web1.get_iframe('outlookFrame') as iframe2:
            IDs = iframe2.find_elements_by_xpath('//*[@id]')
            for items in IDs:
                print items

错误:

^{pr2}$

我试着运行execute_script(),但也没用。我花了很多时间用不同的方法,但我想不出来。在

with web1.get_iframe('outlookFrame') as iframe2:
            javaScript = 'toggleTree("pnl10","usersStatusView.html");'
            web1.execute_script(javaScript)
raise exception_class(message, screen, stacktrace)

错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'location' of undefined

这是我正在处理的菜单。我想打开碎片用户设置视图.html. 我不能直接从网址打开它,因为它打破了配置过程,我必须使用菜单。我正在寻找一个关于最佳方法的建议,因为很明显我的方法不好。在

<div id="nav_head1" class="nav_group" style="display: block;"> <div id="nav_arrow"><a href="javascript:toggleTree('pnl10','usersStatusView.html');"><img src="arrow_down.gif" id="apnl10" alt="" width="8" border="0" height="10"></a></div> <div id="nav_icon"><a href="javascript:toggleTree('pnl10','usersStatusView.html');"><img src="icon_users.gif" alt="" width="20" border="0" height="20"></a></div> <div id="nav_head1_text"><a href="javascript:toggleTree('pnl10','usersStatusView.html');" class="nav_font_head1"> Users</a></div> </div> <div id="nav_head2" class="nav_item" style="display: block;"><div id="nav_head2_textbox"><a href="usersSettingsView.html" onclick="javascript:hiLight(this);" target="tabFrame" class="nav_sub_sett">Settings</a></div> </div>

欢迎所有的想法!谢谢。在


Tags: path方法dividhtmljavascriptclasshref

热门问题