<bdo id='RFrZ7'></bdo><ul id='RFrZ7'></ul>

  • <i id='RFrZ7'><tr id='RFrZ7'><dt id='RFrZ7'><q id='RFrZ7'><span id='RFrZ7'><b id='RFrZ7'><form id='RFrZ7'><ins id='RFrZ7'></ins><ul id='RFrZ7'></ul><sub id='RFrZ7'></sub></form><legend id='RFrZ7'></legend><bdo id='RFrZ7'><pre id='RFrZ7'><center id='RFrZ7'></center></pre></bdo></b><th id='RFrZ7'></th></span></q></dt></tr></i><div id='RFrZ7'><tfoot id='RFrZ7'></tfoot><dl id='RFrZ7'><fieldset id='RFrZ7'></fieldset></dl></div>
    <tfoot id='RFrZ7'></tfoot>

        <small id='RFrZ7'></small><noframes id='RFrZ7'>

        <legend id='RFrZ7'><style id='RFrZ7'><dir id='RFrZ7'><q id='RFrZ7'></q></dir></style></legend>

      1. 在获取所有链接时,忽略循环中的注销链接并继续在 selenium java 中导航

        While fetching all links,Ignore logout link from the loop and continue navigation in selenium java(在获取所有链接时,忽略循环中的注销链接并继续在 selenium java 中导航)
      2. <small id='4p3Sb'></small><noframes id='4p3Sb'>

          • <tfoot id='4p3Sb'></tfoot>
            <legend id='4p3Sb'><style id='4p3Sb'><dir id='4p3Sb'><q id='4p3Sb'></q></dir></style></legend>
              <tbody id='4p3Sb'></tbody>

                <i id='4p3Sb'><tr id='4p3Sb'><dt id='4p3Sb'><q id='4p3Sb'><span id='4p3Sb'><b id='4p3Sb'><form id='4p3Sb'><ins id='4p3Sb'></ins><ul id='4p3Sb'></ul><sub id='4p3Sb'></sub></form><legend id='4p3Sb'></legend><bdo id='4p3Sb'><pre id='4p3Sb'><center id='4p3Sb'></center></pre></bdo></b><th id='4p3Sb'></th></span></q></dt></tr></i><div id='4p3Sb'><tfoot id='4p3Sb'></tfoot><dl id='4p3Sb'><fieldset id='4p3Sb'></fieldset></dl></div>
                  <bdo id='4p3Sb'></bdo><ul id='4p3Sb'></ul>

                  本文介绍了在获取所有链接时,忽略循环中的注销链接并继续在 selenium java 中导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在获取页面中的所有链接并导航到所有链接.其中一个链接是注销.如何跳过/忽略循环中的注销链接?

                  I am fetching all the links in the page and navigating to all links. In that one of the link is Logout. How do i skip/ignore Logout link from the loop?

                  我想跳过注销链接并继续

                  I want to skip Logout link and proceed

                  列出 demovar=driver.findElements(By.tagName("a"));System.out.println(demovar.size());

                  List demovar=driver.findElements(By.tagName("a")); System.out.println(demovar.size());

                     ArrayList<String> hrefs = new ArrayList<String>(); //List for storing all href values for 'a' tag
                  
                        for (WebElement var : demovar) {
                            System.out.println(var.getText()); // used to get text present between the anchor tags
                            System.out.println(var.getAttribute("href"));
                            hrefs.add(var.getAttribute("href")); 
                            System.out.println("*************************************");
                        }
                  
                        int logoutlinkIndex = 0;
                  
                        for (WebElement linkElement : demovar) {
                                 if (linkElement.getText().equals("Log Out")) {
                                             logoutlinkIndex = demovar.indexOf(linkElement);
                                             break;
                                  }
                  
                        }
                  
                        demovar.remove(logoutlinkIndex);
                  
                        //Navigating to each link
                        int i=0;
                        for (String href : hrefs) {
                            driver.navigate().to(href);
                            System.out.println((++i)+": navigated to URL with href: "+href);
                            Thread.sleep(5000); // To check if the navigation is happening properly.
                            System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                  

                  推荐答案

                  如果您想从循环中省略 Logout 链接,而不是将 List 创建为 driver.findElements(By.tagName("a")); 作为替代方案,您可以使用:

                  If you want to leave out the Logout link from the loop instead of creating the List as driver.findElements(By.tagName("a")); as an alternative you can use:

                  driver.findElements(By.xpath("//a[not(contains(.,'Log Out'))]"));
                  

                  <小时>

                  参考

                  您可以在以下位置找到一些相关讨论:


                  Reference

                  You can find a couple of relevant discussions in:

                  • 量角器条件选择器
                  • 如何定位按钮通过 Python 使用 Selenium 的元素
                  • 什么确实 contains(., 'some text') 是指在 Selenium 中使用的 xpath 内
                  • xpath中的dot(.)如何在识别元素和匹配文本时采取多种形式

                  这篇关于在获取所有链接时,忽略循环中的注销链接并继续在 selenium java 中导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <tbody id='kt12Q'></tbody>
                • <legend id='kt12Q'><style id='kt12Q'><dir id='kt12Q'><q id='kt12Q'></q></dir></style></legend>

                      <small id='kt12Q'></small><noframes id='kt12Q'>

                      <tfoot id='kt12Q'></tfoot>
                      • <bdo id='kt12Q'></bdo><ul id='kt12Q'></ul>

                          <i id='kt12Q'><tr id='kt12Q'><dt id='kt12Q'><q id='kt12Q'><span id='kt12Q'><b id='kt12Q'><form id='kt12Q'><ins id='kt12Q'></ins><ul id='kt12Q'></ul><sub id='kt12Q'></sub></form><legend id='kt12Q'></legend><bdo id='kt12Q'><pre id='kt12Q'><center id='kt12Q'></center></pre></bdo></b><th id='kt12Q'></th></span></q></dt></tr></i><div id='kt12Q'><tfoot id='kt12Q'></tfoot><dl id='kt12Q'><fieldset id='kt12Q'></fieldset></dl></div>