Python Selenium无法单击<a href="#" ...=""> with javascript

时间:2018-07-30 21:23:01

标签: python-2.7 selenium-chromedriver

I have the following HTML:

<ul id="TopMenuTabs">
    <li>...</li>
    <li class="active">
        <a href="#" onclick="formaction='topbasic';document.frmEPO.button.value='topbasic'; if( ValidateForm() ) document.frmEPO.submit(); return false;">Reports</a>
    </li>
</ul>

I'm trying to click the second button on a top menu of a site using the following code:

driver.find_element_by_xpath("//ul[@id='TopMenuTabs']/li[1]/a").click().perform()

When I run it, the url adds the "#" to the end so it's recognizing the click() command, but doesn't seem to actually click it or execute the javascript. I've tried using time.sleep for up to 30 seconds, to ensure it isn't just a page-loading problem, with no success. It always moves on to the next line and errors out because the page hasn't changed. Not really sure what to try next!

0 个答案:

没有答案