简体   繁体   中英

Selenium: Cannot access a div in a web page

I would like to automate click on a link with selenium in a web page. The problem I am facing is that Selenium doesn't recognize all elements included in a div. I've tried to locate it with id, cssSelector and even with Xpath it's not working. I've tried also Selenium IDE which seems not able to locate elements included in that div (it locates only the entire div).

Have you an idea please from what this problem can came from?

Here is the HTML section I would like to access to:

<div>
    <script type="text/javascript">
    <script type="text/javascript">
    <div id="ctl00_Main_ctl00_TabTransactions" class="tabs ui-tabs ui-widget ui-widget-content ui-corner-all" style="height: 444px">
    <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
        <li class="ui-corner-top ui-state-default">
        <li class="ui-corner-top ui-tabs-selected ui-state-active">
        <a href="#ctl00_Main_ctl00_PanelTransactionMcc">Mcc</a>
        </li>
        <li class="ui-corner-top ui-state-default">
        <li class="ui-state-default ui-corner-top">
    </ul>
    <div id="ctl00_Main_ctl00_PanelTransactions" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
    <div id="ctl00_Main_ctl00_PanelTransactionMcc" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
    <div id="ctl00_Main_ctl00_TabPanelservice" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
    <div id="ctl00_Main_ctl00_TabPanelLimitsSettings" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
</div>
<div id="ctl00_Main_ctl00_upTrxModal"> </div>
    <input id="hdnimgloaderid" type="hidden" value="loading_transactions">
    <script src="/js/jquery.contextMenu.js" type="text/javascript">
    <script type="text/javascript">
    <script type="text/javascript">
</div>

I am trying to click on <a href="#ctl00_Main_ctl00_PanelTransactionMcc">Mcc</a> with :

driver.findElement(By.linkText("Mcc")).click();

But it's not working neither.

Thank you in advance.

Actually, I finally succeeded to acces to Mcc link. I couldn't access it because it was included into a frame. The problem was solved by switching to the correct frame.

driver.switchTo().frame(0);
System.out.println("Switching successfull");
driver.findElement(By.xpath("/html/body/form/div[3]/div[1]/ul/li[2]/a")).click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM