Selenium cant locate element by label











up vote
1
down vote

favorite












I am trying to locate the tool tip on my page demo.rezi.co on left hand side that says landlords based on the attribute label.
I have drafted the code below.



When I run it, it says that:




Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@label='LANDLORDS']"}




This is my code so far:



// Test Landlord Tooltip
String expectedToolTip = "This is a test";
WebElement landlord = Driver.findElement(By.xpath("//a[@label='LANDLORDS']"));
System.out.println(landlord.getTagName());









share|improve this question




























    up vote
    1
    down vote

    favorite












    I am trying to locate the tool tip on my page demo.rezi.co on left hand side that says landlords based on the attribute label.
    I have drafted the code below.



    When I run it, it says that:




    Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@label='LANDLORDS']"}




    This is my code so far:



    // Test Landlord Tooltip
    String expectedToolTip = "This is a test";
    WebElement landlord = Driver.findElement(By.xpath("//a[@label='LANDLORDS']"));
    System.out.println(landlord.getTagName());









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am trying to locate the tool tip on my page demo.rezi.co on left hand side that says landlords based on the attribute label.
      I have drafted the code below.



      When I run it, it says that:




      Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@label='LANDLORDS']"}




      This is my code so far:



      // Test Landlord Tooltip
      String expectedToolTip = "This is a test";
      WebElement landlord = Driver.findElement(By.xpath("//a[@label='LANDLORDS']"));
      System.out.println(landlord.getTagName());









      share|improve this question















      I am trying to locate the tool tip on my page demo.rezi.co on left hand side that says landlords based on the attribute label.
      I have drafted the code below.



      When I run it, it says that:




      Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@label='LANDLORDS']"}




      This is my code so far:



      // Test Landlord Tooltip
      String expectedToolTip = "This is a test";
      WebElement landlord = Driver.findElement(By.xpath("//a[@label='LANDLORDS']"));
      System.out.println(landlord.getTagName());






      selenium selenium-webdriver xpath mousehover webdriverwait






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 13:55









      DebanjanB

      37.1k73372




      37.1k73372










      asked Nov 8 at 21:51









      Neeru

      61




      61
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Label is not an attribute of the link, it's a child. If you really want to select the a by text LANDLORDS you would have to use something like this:



          "//label[contains(text(),'LANDLORDS')]/ancestor::a"





          share|improve this answer





















          • I am still getting the same error as before even after using the above code. The HTML can be viewed at - demo.rezi.co/#!/tenant. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"label[contains(text(),'LANDLORDS')]/ancestor::a"} (Session info: chrome=70.0.3538.77)
            – Neeru
            Nov 9 at 16:50












          • There's a loader on the page, you need to wait until the element is present before trying to find it
            – Lucas Tierney
            Nov 9 at 18:43


















          up vote
          0
          down vote













          I am still not sure if I have understood the usecase properly. However on the webpage demo.rezi.co you need to Mouse Hover over the element with text as LANDLORDS and then you can extract the Tool Tip and you can use the following solution:





          • Code Block:



            import java.util.List;
            import org.openqa.selenium.By;
            import org.openqa.selenium.WebDriver;
            import org.openqa.selenium.WebElement;
            import org.openqa.selenium.chrome.ChromeDriver;
            import org.openqa.selenium.chrome.ChromeOptions;
            import org.openqa.selenium.interactions.Actions;
            import org.openqa.selenium.support.ui.ExpectedConditions;
            import org.openqa.selenium.support.ui.WebDriverWait;

            public class q53216692_MouseHover {

            public static void main(String args) {

            System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.addArguments("disable-infobars");
            WebDriver Driver = new ChromeDriver(options);
            Driver.get("https://demo.rezi.co/#!/tenant");
            WebElement myElement = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[.='LANDLORDS']")));
            new Actions(Driver).moveToElement(myElement).perform();
            List<WebElement> tool_tip_items = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//label[.='LANDLORDS']//following::div[1]//div[@class='layout-column']/label[1]")));
            for (WebElement tool_tip:tool_tip_items)
            System.out.println(tool_tip.getText());
            }
            }



          • Console Output:



            UPFRONT
            ADVANTAGE







          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216692%2fselenium-cant-locate-element-by-label%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Label is not an attribute of the link, it's a child. If you really want to select the a by text LANDLORDS you would have to use something like this:



            "//label[contains(text(),'LANDLORDS')]/ancestor::a"





            share|improve this answer





















            • I am still getting the same error as before even after using the above code. The HTML can be viewed at - demo.rezi.co/#!/tenant. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"label[contains(text(),'LANDLORDS')]/ancestor::a"} (Session info: chrome=70.0.3538.77)
              – Neeru
              Nov 9 at 16:50












            • There's a loader on the page, you need to wait until the element is present before trying to find it
              – Lucas Tierney
              Nov 9 at 18:43















            up vote
            0
            down vote













            Label is not an attribute of the link, it's a child. If you really want to select the a by text LANDLORDS you would have to use something like this:



            "//label[contains(text(),'LANDLORDS')]/ancestor::a"





            share|improve this answer





















            • I am still getting the same error as before even after using the above code. The HTML can be viewed at - demo.rezi.co/#!/tenant. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"label[contains(text(),'LANDLORDS')]/ancestor::a"} (Session info: chrome=70.0.3538.77)
              – Neeru
              Nov 9 at 16:50












            • There's a loader on the page, you need to wait until the element is present before trying to find it
              – Lucas Tierney
              Nov 9 at 18:43













            up vote
            0
            down vote










            up vote
            0
            down vote









            Label is not an attribute of the link, it's a child. If you really want to select the a by text LANDLORDS you would have to use something like this:



            "//label[contains(text(),'LANDLORDS')]/ancestor::a"





            share|improve this answer












            Label is not an attribute of the link, it's a child. If you really want to select the a by text LANDLORDS you would have to use something like this:



            "//label[contains(text(),'LANDLORDS')]/ancestor::a"






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 9 at 2:19









            Lucas Tierney

            1,58788




            1,58788












            • I am still getting the same error as before even after using the above code. The HTML can be viewed at - demo.rezi.co/#!/tenant. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"label[contains(text(),'LANDLORDS')]/ancestor::a"} (Session info: chrome=70.0.3538.77)
              – Neeru
              Nov 9 at 16:50












            • There's a loader on the page, you need to wait until the element is present before trying to find it
              – Lucas Tierney
              Nov 9 at 18:43


















            • I am still getting the same error as before even after using the above code. The HTML can be viewed at - demo.rezi.co/#!/tenant. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"label[contains(text(),'LANDLORDS')]/ancestor::a"} (Session info: chrome=70.0.3538.77)
              – Neeru
              Nov 9 at 16:50












            • There's a loader on the page, you need to wait until the element is present before trying to find it
              – Lucas Tierney
              Nov 9 at 18:43
















            I am still getting the same error as before even after using the above code. The HTML can be viewed at - demo.rezi.co/#!/tenant. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"label[contains(text(),'LANDLORDS')]/ancestor::a"} (Session info: chrome=70.0.3538.77)
            – Neeru
            Nov 9 at 16:50






            I am still getting the same error as before even after using the above code. The HTML can be viewed at - demo.rezi.co/#!/tenant. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"label[contains(text(),'LANDLORDS')]/ancestor::a"} (Session info: chrome=70.0.3538.77)
            – Neeru
            Nov 9 at 16:50














            There's a loader on the page, you need to wait until the element is present before trying to find it
            – Lucas Tierney
            Nov 9 at 18:43




            There's a loader on the page, you need to wait until the element is present before trying to find it
            – Lucas Tierney
            Nov 9 at 18:43












            up vote
            0
            down vote













            I am still not sure if I have understood the usecase properly. However on the webpage demo.rezi.co you need to Mouse Hover over the element with text as LANDLORDS and then you can extract the Tool Tip and you can use the following solution:





            • Code Block:



              import java.util.List;
              import org.openqa.selenium.By;
              import org.openqa.selenium.WebDriver;
              import org.openqa.selenium.WebElement;
              import org.openqa.selenium.chrome.ChromeDriver;
              import org.openqa.selenium.chrome.ChromeOptions;
              import org.openqa.selenium.interactions.Actions;
              import org.openqa.selenium.support.ui.ExpectedConditions;
              import org.openqa.selenium.support.ui.WebDriverWait;

              public class q53216692_MouseHover {

              public static void main(String args) {

              System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
              ChromeOptions options = new ChromeOptions();
              options.addArguments("start-maximized");
              options.addArguments("disable-infobars");
              WebDriver Driver = new ChromeDriver(options);
              Driver.get("https://demo.rezi.co/#!/tenant");
              WebElement myElement = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[.='LANDLORDS']")));
              new Actions(Driver).moveToElement(myElement).perform();
              List<WebElement> tool_tip_items = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//label[.='LANDLORDS']//following::div[1]//div[@class='layout-column']/label[1]")));
              for (WebElement tool_tip:tool_tip_items)
              System.out.println(tool_tip.getText());
              }
              }



            • Console Output:



              UPFRONT
              ADVANTAGE







            share|improve this answer

























              up vote
              0
              down vote













              I am still not sure if I have understood the usecase properly. However on the webpage demo.rezi.co you need to Mouse Hover over the element with text as LANDLORDS and then you can extract the Tool Tip and you can use the following solution:





              • Code Block:



                import java.util.List;
                import org.openqa.selenium.By;
                import org.openqa.selenium.WebDriver;
                import org.openqa.selenium.WebElement;
                import org.openqa.selenium.chrome.ChromeDriver;
                import org.openqa.selenium.chrome.ChromeOptions;
                import org.openqa.selenium.interactions.Actions;
                import org.openqa.selenium.support.ui.ExpectedConditions;
                import org.openqa.selenium.support.ui.WebDriverWait;

                public class q53216692_MouseHover {

                public static void main(String args) {

                System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
                ChromeOptions options = new ChromeOptions();
                options.addArguments("start-maximized");
                options.addArguments("disable-infobars");
                WebDriver Driver = new ChromeDriver(options);
                Driver.get("https://demo.rezi.co/#!/tenant");
                WebElement myElement = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[.='LANDLORDS']")));
                new Actions(Driver).moveToElement(myElement).perform();
                List<WebElement> tool_tip_items = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//label[.='LANDLORDS']//following::div[1]//div[@class='layout-column']/label[1]")));
                for (WebElement tool_tip:tool_tip_items)
                System.out.println(tool_tip.getText());
                }
                }



              • Console Output:



                UPFRONT
                ADVANTAGE







              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                I am still not sure if I have understood the usecase properly. However on the webpage demo.rezi.co you need to Mouse Hover over the element with text as LANDLORDS and then you can extract the Tool Tip and you can use the following solution:





                • Code Block:



                  import java.util.List;
                  import org.openqa.selenium.By;
                  import org.openqa.selenium.WebDriver;
                  import org.openqa.selenium.WebElement;
                  import org.openqa.selenium.chrome.ChromeDriver;
                  import org.openqa.selenium.chrome.ChromeOptions;
                  import org.openqa.selenium.interactions.Actions;
                  import org.openqa.selenium.support.ui.ExpectedConditions;
                  import org.openqa.selenium.support.ui.WebDriverWait;

                  public class q53216692_MouseHover {

                  public static void main(String args) {

                  System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
                  ChromeOptions options = new ChromeOptions();
                  options.addArguments("start-maximized");
                  options.addArguments("disable-infobars");
                  WebDriver Driver = new ChromeDriver(options);
                  Driver.get("https://demo.rezi.co/#!/tenant");
                  WebElement myElement = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[.='LANDLORDS']")));
                  new Actions(Driver).moveToElement(myElement).perform();
                  List<WebElement> tool_tip_items = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//label[.='LANDLORDS']//following::div[1]//div[@class='layout-column']/label[1]")));
                  for (WebElement tool_tip:tool_tip_items)
                  System.out.println(tool_tip.getText());
                  }
                  }



                • Console Output:



                  UPFRONT
                  ADVANTAGE







                share|improve this answer












                I am still not sure if I have understood the usecase properly. However on the webpage demo.rezi.co you need to Mouse Hover over the element with text as LANDLORDS and then you can extract the Tool Tip and you can use the following solution:





                • Code Block:



                  import java.util.List;
                  import org.openqa.selenium.By;
                  import org.openqa.selenium.WebDriver;
                  import org.openqa.selenium.WebElement;
                  import org.openqa.selenium.chrome.ChromeDriver;
                  import org.openqa.selenium.chrome.ChromeOptions;
                  import org.openqa.selenium.interactions.Actions;
                  import org.openqa.selenium.support.ui.ExpectedConditions;
                  import org.openqa.selenium.support.ui.WebDriverWait;

                  public class q53216692_MouseHover {

                  public static void main(String args) {

                  System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
                  ChromeOptions options = new ChromeOptions();
                  options.addArguments("start-maximized");
                  options.addArguments("disable-infobars");
                  WebDriver Driver = new ChromeDriver(options);
                  Driver.get("https://demo.rezi.co/#!/tenant");
                  WebElement myElement = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[.='LANDLORDS']")));
                  new Actions(Driver).moveToElement(myElement).perform();
                  List<WebElement> tool_tip_items = new WebDriverWait(Driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//label[.='LANDLORDS']//following::div[1]//div[@class='layout-column']/label[1]")));
                  for (WebElement tool_tip:tool_tip_items)
                  System.out.println(tool_tip.getText());
                  }
                  }



                • Console Output:



                  UPFRONT
                  ADVANTAGE








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 13:57









                DebanjanB

                37.1k73372




                37.1k73372






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216692%2fselenium-cant-locate-element-by-label%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Hercules Kyvelos

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud