Question about finding a button

62 views
Skip to first unread message

David Patterson

unread,
Jul 16, 2015, 11:51:55 AM7/16/15
to webd...@googlegroups.com
I'm puzzled by the following:

1) I try:
             WebElement loginButton = driver.findElement(By.ByLinkText.linkText( "Log in" ) );

        and this fails because the element cannot be found.


2) I try:

       List<WebElement> buttons = driver.findElement( By.ByTagName.tagName( "button" ));

       for( WebElement button : buttons ) {

            if ( button instanceOf RemoteWebElement ) {

                RemoteWebElement remoteButton = (RemoteWebElement) button;

                if (remoteButton.isDisplayed() && remoteButton.getAttribute( "class" ).equals("xx") ) {

                     String text = remoteButton.getText();

                      ** text = "Log in".

                     ...

                }

            }

       }

       and it works.


Can anyone explain why one works and the other doesn't?


Dave P

Shawn McCarthy

unread,
Jul 16, 2015, 12:14:30 PM7/16/15
to webd...@googlegroups.com

       List<WebElement> buttons = driver.findElement( By.ByTagName.tagName( "button" ));


should fail because findElement will return a single element. Also, the first one assumes its a link (a tag). In the 2nd one, you are looking for a button tag.

Rohit Patwari

unread,
Jul 16, 2015, 12:22:00 PM7/16/15
to webd...@googlegroups.com

By.linktext is only used for links ( tag=a)

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

David Patterson

unread,
Jul 16, 2015, 3:31:00 PM7/16/15
to webd...@googlegroups.com
Thanks for the clarification.

Dave P
Reply all
Reply to author
Forward
0 new messages