简体   繁体   English

Selenium:无法访问网页中的div

[英]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. 我面临的问题是Selenium无法识别div中包含的所有元素。 I've tried to locate it with id, cssSelector and even with Xpath it's not working. 我试图用id,cssSelector定位它,甚至使用Xpath也无法正常工作。 I've tried also Selenium IDE which seems not able to locate elements included in that div (it locates only the entire div). 我也尝试了Selenium IDE,它似乎无法定位该div中包含的元素(它只能定位整个div)。

Have you an idea please from what this problem can came from? 请问这个问题可能来自什么?

Here is the HTML section I would like to access to: 这是我要访问的HTML部分:

<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 : 我试图点击<a href="#ctl00_Main_ctl00_PanelTransactionMcc">Mcc</a>

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. 实际上,我终于成功访问了Mcc链接。 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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