WebElement..getText() sometimes returns empty string when screenshot shows string not empty

16,850 views
Skip to first unread message

BillR

unread,
Jan 8, 2013, 5:21:25 PM1/8/13
to webd...@googlegroups.com
I am finding that WebElement.getText() returns an empty string sometimes, but when it happens and I take a screenshot, the text is there. When I getAttribute("class") I see that I have found the right element, but it doesn't give me the text. Not sure if this would be a webdriver of FF bug. (A parent div has 'active' appended to its class when the popup containing the text appears, and this seems reliable.)

Has anyone seen this sort of thing? I see it running 1 test thread as well as >1.

Thanks,
Bill

FF 17.0
selenium-server-standalone-2.28.0.jar
Ubuntu with Xvfb

Html:

<div id="summaryTip" class="xpop xtip size-medium useCloseBox xpop-position-bottom active" style="width: 275px; top: 305px; left: 738px; z-index: 20;">
  <div class="xpop-content-container">
    <a class="xpop-close">x</a>
    <div class="xpop-title"></div>
    <div class="xpop-content">You will see a summary of your transfer as you proceed. </div>
  </div>
  <div class="xpop-pointer" ...</div>
</div>

Code:

    @FindBy(id = "summaryTip")
    WebElement receiptSummaryHolder;
    //@FindBy(xpath = "//div[@id='summaryTip']/div/div[2]")
    @FindBy(css = "#summaryTip .xpop-content")
    WebElement receiptSummaryTip;
    boolean receiptSummaryTipActive() {
        String s = receiptSummaryHolder.getAttribute("class");
        System.out.println("### summaryTip class: " + s);
        return s.contains("active");
    }
    String getReceiptSummaryTip() {
        String s = receiptSummaryTip.getText();
        if (s == null  ||  s.trim().length() == 0) {
            System.out.println("### empty, class = " + receiptSummaryTip.getAttribute("class"));
            WebElement we = receiptSummaryHolder.findElement(By.className("xpop-content"));
            System.out.println("### by.class [" + we.getText() + "] [" + we.getAttribute("class") + "]");
            return we.getText();
        }
        System.out.println("### NOT EMPTY: [" + s + "]");
        return s;
    }

Output:

    ### empty, class = xpop-content
    ### by.class [] [xpop-content]
    Screenshot: screenshots/1357682907182_8_no_rcpt_summary_1.png [shows text]
    ### empty, class = xpop-content
    ### by.class [] [xpop-content]
    ### summaryTip class: xpop xtip size-medium useCloseBox xpop-position-bottom active



BillR

unread,
Jan 8, 2013, 7:47:55 PM1/8/13
to webd...@googlegroups.com
Another thing: problem not seen on Windows 7 with FF 13.0.1 and using FirefoxDriver directly.

ASP

unread,
Jan 9, 2013, 12:20:40 PM1/9/13
to webd...@googlegroups.com
//div[@id='summaryTip']//div[@class='xpop-content'][text()='You will see a summary of your transfer as you proceed. '] 

try to use above xpath and see 

in my experience sometimes selenium tries to read even before page is loaded ... so I would recommend use proper wait methods ... you can try something like Thread.sleep(2000) just to verify

see how that goes


ASP

BillR

unread,
Jan 9, 2013, 1:06:19 PM1/9/13
to webd...@googlegroups.com
Thanks, I know I'm getting the right element because getAttribute("class") shows the right thing. I know there isn't a timing issue because I did

    getText() - nothing
    screenshot - text visible
    getText() - nothing

I tried this: WebElement we = receiptSummaryHolder.findElement(By.xpath("//div[text()='You will see a summary of your transfer as you proceed.']"));
but got NoSuchElementException. So from Webdriver's point of view, the text doesn't seem to be visible in these intermittent cases.

Bill

Smita Sinha

unread,
Jan 9, 2013, 1:17:31 PM1/9/13
to webd...@googlegroups.com
Try clicking the element before getText.
This worked for me .
I faced similar situation sometime back.

-Smita

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/0n7rkJsaHqkJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

BillR

unread,
Jan 9, 2013, 3:41:17 PM1/9/13
to webd...@googlegroups.com
Thanks Smita,

I tried this for this case and in another place where this was happening, and got ElementNotVisibleException, which is interesting because getText() didn't cause the exception. In the second case, the particular field is tied to javascript and balloons out when another field is changed, so 'invisible' in this case seems to mean it is actively ballooning. Solution so far in that case is a sleep/retry loop, since the value eventually appears. For the original case here is what I tried and output:
    void crazyGetReceiptSummaryTip() {
        for (int i=0; i<10; i++) {
            try {

                WebElement we = receiptSummaryHolder.findElement(By.xpath("//div[text()='You will see a summary of your transfer as you proceed.']"));
                System.out.println("### EXPT got elt based on text.");
                return;
            } catch (NoSuchElementException nsee) {
                System.out.println("### EXPT not got elt based on text.");
            }
            try {
                receiptSummaryTip.click();
                System.out.println("### EXPT elt clickable.");
            } catch (ElementNotVisibleException enve) {
                System.out.println("### EXPT elt not visible for click.");

            }
            String s = receiptSummaryTip.getText();
            if (s == null  ||  s.trim().length() == 0) {
                System.out.println("### EXPT not got txt based on click.");
            } else {
                System.out.println("### EXPT GOT txt based on click: " + s);
                return;
            }
            s = receiptSummaryTip.getText();
            if (s != null  &&  s.length() > 0) {
                System.out.println("### EXPT GOT w/ plain retry: " + s);
            }
            sleep(1000);
        }
        System.out.println("### EXPT FAIL");
    }

    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT not got elt based on text.
    ### EXPT elt not visible for click.
    ### EXPT not got txt based on click.
    ### EXPT FAIL

Bill

Andrew Fowler

unread,
Jan 9, 2013, 3:47:16 PM1/9/13
to webd...@googlegroups.com
Is

class="xpop-content"

definitely unique to the page?  (so find elements only returns a single element)


Does

//div[contains(@class,'You will see a summary')]

throw the not found exception?

Pankaj Nakhat

unread,
Jan 9, 2013, 3:58:24 PM1/9/13
to webd...@googlegroups.com

Try getAttribute("values")


Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/y2wom8mFfS0J.

BillR

unread,
Jan 9, 2013, 4:00:28 PM1/9/13
to webd...@googlegroups.com
Inline:


On Wednesday, January 9, 2013 12:47:16 PM UTC-8, Andrew Fowler wrote:
Is

class="xpop-content"

definitely unique to the page?  (so find elements only returns a single element)

I'm searching from a parent WebElement, and it is unique within that context, see original html above.



Does

//div[contains(@class,'You will see a summary')]

throw the not found exception?

The class doesn't contain the string, so why expect it?

Bill
 

BillR

unread,
Jan 9, 2013, 4:06:03 PM1/9/13
to webd...@googlegroups.com
getAttribute("value") also fails.

ASP

unread,
Jan 9, 2013, 4:27:06 PM1/9/13
to webd...@googlegroups.com
I had similar issue .... ElementNotVisibleException looks like selenium is going faster than a page load ... make sure u make selenium wait until whole page is rendered. 

I would again recommend Thread.sleep atleast u can verify 

Andrew Fowler

unread,
Jan 9, 2013, 4:34:52 PM1/9/13
to webd...@googlegroups.com

The class doesn't contain the string, so why expect it?

Sorry, my mistake, I meant  //div[contains(text(),'You will see a summary')].  Just wanted to make sure the trailing whitespace on the text wasn't causing a problem doing the find element by text, above.

BillR

unread,
Jan 9, 2013, 5:41:18 PM1/9/13
to webd...@googlegroups.com
Worth a try, but didn't work.

Smita Sinha

unread,
Jan 9, 2013, 11:28:33 PM1/9/13
to webd...@googlegroups.com
Is it a frame? Can you share the xpath?

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/IKXWwcRPro8J.

darrell

unread,
Jan 10, 2013, 11:33:00 AM1/10/13
to webdriver
Hey Bill,

This makes a little sense. If the element is not visible then the
GetText is going to return nothing. You could probably wrap the
GetText with a IsDisplayed. If IsDisplayed is false then GetText is
going to return nothing.

Now the question is why do certain configurations tell you the element
is not visible. I have encountered this occasionally and it usually
turned out that someone (or a library) were doing something with
violated the HTML or javascript standards but some web browsers did
the 'right' thing. So the real problem was not that FF on Linux was
failing but that that FF on Windows was working. That is the defect is
you were getting a false positive on Windows and not that you were
getting a failure on Linux.

If you are not a guru on the HTML standard but have someone who is,
try bringing them in and see if they can spot something. Or try using
TidyHTML to examine the DOM on the machines. It might give you a
warning which you (or your HTML guru) will immediately recognize as a
problem. Fixing the HTML code might be the solution to your problem.

Darrell
> > On Wed, Jan 9, 2013 at 11:36 PM, BillR <ro...@cgl.ucsf.edu <javascript:>>wrote:
>
> >> Thanks, I know I'm getting the right element because
> >> getAttribute("class") shows the right thing. I know there isn't a timing
> >> issue because I did
>
> >>     getText() - nothing
> >>     screenshot - text visible
> >>     getText() - nothing
>
> >> I tried this: WebElement we =
> >> receiptSummaryHolder.findElement(By.xpath("//div[text()='You will see a
> >> summary of your transfer as you proceed.']"));
> >> but got NoSuchElementException. So from Webdriver's point of view, the
> >> text doesn't seem to be visible in these intermittent cases.
>
> >> Bill
>
> >> On Wednesday, January 9, 2013 9:20:40 AM UTC-8, ASP wrote:
>
> >>> //div[@id='summaryTip']//div[@**class='xpop-content'][text()='**You
> >>> will see a summary of your transfer as you proceed. ']
>
> >>> try to use above xpath and see
>
> >>> in my experience sometimes selenium tries to read even before page is
> >>> loaded ... so I would recommend use proper wait methods ... you can try
> >>> something like Thread.sleep(2000) just to verify
>
> >>> see how that goes
>
> >>> ASP
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "webdriver" group.
> >> To view this discussion on the web visit
> >>https://groups.google.com/d/msg/webdriver/-/0n7rkJsaHqkJ.
>
> >> To post to this group, send email to webd...@googlegroups.com<javascript:>
> >> .
> >> To unsubscribe from this group, send email to
> >> webdriver+...@googlegroups.com <javascript:>.

Bill Ross

unread,
Jan 10, 2013, 2:27:19 PM1/10/13
to webd...@googlegroups.com
It's not a frame. Xpaths are in the thread, don't have them handy.
It works most of the time, goes blind sometimes.

Bill

Bill Ross

unread,
Jan 10, 2013, 2:44:31 PM1/10/13
to webd...@googlegroups.com
Thanks Darrell,

The weird thing is that the element is visible in the literal sense -
it appears in the screenshot, and most of the time I can get it with
getText() too. I'll check what isDisplayed says next.

We have very skilful and helpful webdevs, and I haven't gotten an
answer there.

Bill
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

BillR

unread,
Jan 10, 2013, 5:46:10 PM1/10/13
to webd...@googlegroups.com


On Thursday, January 10, 2013 11:44:31 AM UTC-8, BillR wrote:
Thanks Darrell,

The weird thing is that the element is visible in the literal sense -
it appears in the screenshot, and most of the time I can get it with
getText() too. I'll check what isDisplayed says next.

It is true when I get the text, false when getText() comes back empty.
I might have expected an ElementNotVisibleException in that case.
The fact remains the text is visible on the screen.

Bill
 
> > � � void crazyGetReceiptSummaryTip() {
> > � � � � for (int i=0; i<10; i++) {
> > � � � � � � try {
> > � � � � � � � � WebElement we =
> > receiptSummaryHolder.findElement(By.xpath("//div[text()='You will see a
> > summary of your transfer as you proceed.']"));
> > � � � � � � � � System.out.println("### EXPT got elt based on text.");
> > � � � � � � � � return;
> > � � � � � � } catch (NoSuchElementException nsee) {
> > � � � � � � � � System.out.println("### EXPT not got elt based on text.");
> > � � � � � � }
> > � � � � � � try {
> > � � � � � � � � receiptSummaryTip.click();
> > � � � � � � � � System.out.println("### EXPT elt clickable.");
> > � � � � � � } catch (ElementNotVisibleException enve) {
> > � � � � � � � � System.out.println("### EXPT elt not visible for click.");
> > � � � � � � }
> > � � � � � � String s = receiptSummaryTip.getText();
> > � � � � � � if (s == null �|| �s.trim().length() == 0) {
> > � � � � � � � � System.out.println("### EXPT not got txt based on click.");
> > � � � � � � } else {
> > � � � � � � � � System.out.println("### EXPT GOT txt based on click: " + s);
> > � � � � � � � � return;
> > � � � � � � }
> > � � � � � � s = receiptSummaryTip.getText();
> > � � � � � � if (s != null �&& �s.length() > 0) {
> > � � � � � � � � System.out.println("### EXPT GOT w/ plain retry: " + s);
> > � � � � � � }
> > � � � � � � sleep(1000);
> > � � � � }
> > � � � � System.out.println("### EXPT FAIL");
> > � � }
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT not got elt based on text.
> >
> > � � ### EXPT elt not visible for click.
> > � � ### EXPT not got txt based on click.
> >
> > � � ### EXPT FAIL
> >
> > Bill
> >
> >
> >
> >
> >
> >
> >
> > On Wednesday, January 9, 2013 10:17:31 AM UTC-8, Smita Sinha wrote:
> >
> > > Try clicking the element before getText.
> > > This worked for me .
> > > I faced similar situation sometime back.
> >
> > > -Smita
> >
> > > On Wed, Jan 9, 2013 at 11:36 PM, BillR <ro...@cgl.ucsf.edu <javascript:>>wrote:
> >
> > >> Thanks, I know I'm getting the right element because
> > >> getAttribute("class") shows the right thing. I know there isn't a timing
> > >> issue because I did
> >
> > >> � � getText() - nothing
> > >> � � screenshot - text visible
> > >> � � getText() - nothing
> >
> > >> I tried this: WebElement we =
> > >> receiptSummaryHolder.findElement(By.xpath("//div[text()='You will see a
> > >> summary of your transfer as you proceed.']"));
> > >> but got NoSuchElementException. So from Webdriver's point of view, the
> > >> text doesn't seem to be visible in these intermittent cases.
> >
> > >> Bill
> >
> > >> On Wednesday, January 9, 2013 9:20:40 AM UTC-8, ASP wrote:
> >
> > >>> //div[@id='summaryTip']//div[@**class='xpop-content'][text()='**You
> > >>> will see a summary of your transfer as you proceed. ']
> >
> > >>> try to use above xpath and see
> >
> > >>> in my experience sometimes selenium tries to read even before page is
> > >>> loaded ... so I would recommend use proper wait methods ... you can try
> > >>> something like Thread.sleep(2000) just to verify
> >
> > >>> see how that goes
> >
> > >>> ASP
> >
> > >> �--
> > >> You received this message because you are subscribed to the Google Groups
> > >> "webdriver" group.
> > >> To view this discussion on the web visit
> > >>https://groups.google.com/d/msg/webdriver/-/0n7rkJsaHqkJ.
> >
> > >> To post to this group, send email to webd...@googlegroups.com<javascript:>
> > >> .
> > >> To unsubscribe from this group, send email to
> > >> webdriver+...@googlegroups.com <javascript:>.
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/webdriver?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

darrell

unread,
Jan 11, 2013, 11:59:26 AM1/11/13
to webdriver
This was the case for me as well. The text was visible on the screen
for all browsers but for one browser it claimed the element was
invisible through Selenium. The devs looked at it as well and they
seemed stumped. I think we finally found that we were violating some
little known HTML rule that every browser ignored but Selenium did
not. When we fixed that HTML it started working correctly. I actually
had to walk WAY up the DOM to find the error which cascaded down to
the element I was trying to interact with. I cannot remember the
details now but it was something about putting an attribute on a tag
which really shouldn't have that attribute and it wasn't anything to
do with style or visibility.

Darrell

BillR

unread,
Jan 16, 2013, 6:49:06 PM1/16/13
to webd...@googlegroups.com
Thanks Darrell,


>> Or try using
> > TidyHTML to examine the DOM on the machines. It might give you a
> > warning which you (or your HTML guru) will immediately recognize as a
> > problem. Fixing the HTML code might be the solution to your problem.

FWIW here's what I got from HTML Tidy:

Warning: <meta> isn't allowed in <div> elements;
Info: <div> previously mentioned; Warning: <a> proprietary attribute "lid"; Warning: <a> proprietary attribute "lid"; Warning: <a> proprietary attribute "lid"; Warning: <a> proprietary attribute "lid"; Warning: <a> proprietary attribute "lid"; Warning: <a> proprietary attribute "lid"; Warning: <a> proprietary attribute "lid"; Warning: <input> proprietary attribute "placeholder"; Warning: <input> proprietary attribute "placeholder"; Warning: <a> proprietary attribute "data-xtooltip-size"; Warning: <a> proprietary attribute "data-xtooltip-click-disable"


The first one looks especially promising to me - not sure of the significance of the proprietary attributes, which are all onthings that wouldn't contain the element in question.

Bill

BillR

unread,
Jan 16, 2013, 7:11:12 PM1/16/13
to webd...@googlegroups.com
Same behavior seen in Chrome as FF. Version 26.0.1380.0 (176206)

Bill

darrell

unread,
Jan 17, 2013, 7:09:51 PM1/17/13
to webdriver
The first one looks suspicious to me as well. The proprietary
attributes could be a little suspicious as well but I've never seen
them be a problem. The ordering of tags (META inside a DIV) can
definitely put the DOM (and Selenium) in a bad state. The proprietary
attributes should just get ignored. It is usually from something like:

<a href="http://www.google.ca" qa-data-locator="clickme">click me</
a>

TidyHTML complains about things like qa-data-locator because it is not
a standard attribute but I use them all the time to make my locators
unique, stable and short. If I was writing an HTML parser I would
probably write it so the default behaviour, i.e. the behaviour for an
attribute I don't know what to do with, would be to just throw it away
and do nothing. I would hope other browsers do the same thing.

Darrell

Bill Ross

unread,
Jan 19, 2013, 3:09:44 PM1/19/13
to webd...@googlegroups.com
Unfortunately the meta in a div is claimed to be needed. Next I'll see
if I can get an experimental setup without it, to see if it fixes the
problem.

Bill
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

BillR

unread,
Jan 22, 2013, 7:41:39 PM1/22/13
to webd...@googlegroups.com
Tried without the meta, and it still happened. I dumped class and some other attributes from the element in question up to the html element, and it was all the same whether or not the element was visible (starting at bottom):

    @@@ div class [xpop-content] readonly=null hidden=null disabled=null

    @@@ div class [xpop-content-container] readonly=null hidden=null disabled=null

    @@@ div class [xpop xtip size-medium useCloseBox xpop-position-bottom active] readonly=null hidden=null disabled=null

    @@@ body class [lang-en isDesk layout-wide layout-leather svg-true placeholder] readonly=null hidden=null disabled=null

    @@@ html class [] readonly=null hidden=null disabled=null


Thanks to Mike and Luke for suggesting how to work up to the top of the tree: [elt.findElement(By.xpath(".."))]

Bill
> To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

BillR

unread,
Jan 22, 2013, 7:54:57 PM1/22/13
to webd...@googlegroups.com
Still not sure why Webdriver thinks the element is invisible: no element up to the top is hidden or disabled, and the element in the chain that has a style shows non-0 size in visible and invisible cases, though the top is different:

Parent of Visible: @@@ div class [xpop xtip size-medium useCloseBox xpop-position-bottom active] style [width: 275px; top: 357px; left: 336px; z-index: 20;] readonly=null hidden=null disabled=null
 
Parent of Invisible: @@@ div class [xpop xtip size-medium useCloseBox xpop-position-bottom active] style [width: 275px; top: 305px; left: 336px; z-index: 20;] readonly=null hidden=null disabled=null

Bill

BillR

unread,
Jan 22, 2013, 8:07:51 PM1/22/13
to webd...@googlegroups.com
Also see top: 305px in parent of visible element.

BillR

unread,
Jan 23, 2013, 3:16:39 PM1/23/13
to webd...@googlegroups.com
I have found a clue that isn't an explanation, but could be helpful to others.

Since I have a randomly-driveable page object architecture, I can analyze different paths taken to the invisibility problem. In 95/96 cases, it has just clicked on the head of an open accordion element (same one each time), i.e. no action is expected, but on checking state the visibility problem is encountered. Here is the HTML of the accordion:

<div class="section section-active section-visited section-recipient" id="section-recipient">
  <h2 class="section-heading">
    <a href="/send/getstarted/recipient" rel="recipient" class="section-heading-title section-heading-link">
      <span class="section-arrow">&nbsp;</span>
      <span class="">Who is receiving the money?</span>
    </a>
  </h2>
  <div class="section-content clearfix  placeholder" style="height: 445px;">
  ...

I was clicking on both the enclosing div and the anchor, since they are easily-uniquely-defined, and since I was looking at a problem where clicking on closed accordions wasn't opening them. When I change it to just clicking on the logically 'most visible' element, i.e. the span that holds the accordion title, I don't see the error:

  xpath = "//a[@href='/send/getstarted/recipient']/span[2]

Bill

darrell

unread,
Jan 25, 2013, 8:03:28 PM1/25/13
to webdriver
First, thanks for sharing this. If I ever see this it will hopefully
help me solve the problem or at least work around it.

Second, this is the first time a thread has exceeded one page (25
messages) for me. Impressive.

Third, I'm still learning about javascript and various libraries
(angular, ace, play, etc.). I have been seeing more and more libraries
that stump Selenium. I can see this as a good topic to better
understand. Maybe pair with someone who understand the libraries (and
probably callbacks) in javascript which work with the section classes.
Or is this an HTML5 thing?

Darrell
> ...
>
> read more »

BillR

unread,
Jan 29, 2013, 1:56:40 PM1/29/13
to webd...@googlegroups.com
FWIW the only js libraries involved on the page are jQuery and LazyLoad.js, not sure if it's related to them. Ditto HTML5; webdev says no obvious connection.

Bill

BillR

unread,
Jan 29, 2013, 2:13:48 PM1/29/13
to webd...@googlegroups.com
Also: though I've solved for the predominant case of clicking on a parent element of the box in question, I still see it for another case where I select the same option twice in a row from a dropdown within the accordion (i.e. clicking on a sibling of the sometimes-invisible element). This case is tricky because the select element is mediated by javascript to look bigger than the normal select, and rather than trying to manipulate via the visible js dropdown, I make the underlying selector visible, and also click on the js dropdown arrow to trigger other events on the page:

    @FindBy(id="country")
    WebElement countrySelect;
    @FindBy(id="pullArrow")
    WebElement countryPullArrow;

    ((JavascriptExecutor)driver).executeScript("jQuery(\"#country\").show();");
    Select sel = new Select(countrySelect);

    countryPullArrow.click(); // this causes pending 1st/last name to go to receipt
    sel.selectByVisibleText(val);

Debugging this may add another page to this thread :-)

Bill

BillR

unread,
Jan 29, 2013, 3:23:36 PM1/29/13
to webd...@googlegroups.com
The wonky behavior is seen on linux with FF but not Chrome, and not Windows FF/Chrome.

If I don't click on the js-hooked 'country pull arrow' it works to select the same country twice in a row on linux/FF. So clicking the arrow is linked to which country is selected from the underlying select.

I might simply stick to running Chrome on linux to work around it.

Bill

Mike Riley

unread,
Jan 29, 2013, 3:55:06 PM1/29/13
to webd...@googlegroups.com
What are the versions of FF on the two systems?  I have found that Linux often lags in the version of Firefox it has installed.  Maybe this is a variation in how different FF versions behave.

Mike

BillR

unread,
Jan 29, 2013, 4:14:51 PM1/29/13
to webd...@googlegroups.com
FF/linux = Mozilla Firefox 17.0
FF/Windows = 13.0.1

With Chrome it looks like no locator info is printed on NoSuchElementException, which is a pain for debug since I have an array of elements that I check. Here is what I get:
 
org.openqa.selenium.NoSuchElementException: The element could not be found (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 1.03 seconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 20:21:18'
    System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.35-32-generic', java.version: '1.6.0_37'
    Session ID: f47584bdae76c5dd4190f1fa74aacd9b
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities [{platform=LINUX, chrome.chromedriverVersion=23.0.1240.0, acceptSslCerts=false, javascriptEnabled=true, browserName=chrome, rotatable=false, locationContextEnabled=false, version=26.0.1380.0, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, chrome.nativeEvents=false, applicationCacheEnabled=false, takesScreenshot=true}]
    
Bill

Hao Li

unread,
Oct 17, 2013, 12:09:06 PM10/17/13
to webd...@googlegroups.com
Did anybody resolved this issue ?  I faced same thing.  I want get the text of the  object tag .  getText() still empty ,  also  getPropertie("value") .   

But could get the classid ,  and locate object tag  by tag "object" , and by id"QvodPlayer". 

===============================================

     <object classid="clsid:F3D0D36F-23F8-4682-A195-74C92B03D4AF" id="QvodPlayer" width="530" height="60">
                              <param name="url" value="qvod://1677854287|12C48B949D46FC9872D9C65111E004E63AC276F4|ddddd.rmvb|"/>
                              <param name="autoplay" value="1"/>
                              <param name="showcontrol" value="1"/>
                              <param name="nextwebpage" value="javascript:;"/>
                              <embed url="qvod://1677854287|12C48B949D46FC9872D9C65111E004E63AC276F4|dddd.rmvb|" type="application/qvod-plugin" showcontrol="1" autoplay="1" width="100%"/>
                            </object>
=====================================================


        driver.get("http://*****");
       
     //  driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

       System.out.println(driver.getPageSource());   // tag object visible 
       
       WebElement element = driver.findElement(By.id("QvodPlayer"));
       
       element.click();
      
       System.out.println(" displayed ???  "+element.isDisplayed());
 System.out.println("===================================+++"+element.getAttribute("value")+" "+element.getText()+"  "+ element.getTagName()+" "+element.getAttribute("classid"));

===============================faint !!!  empty text ==========================
     

Syagin Kumar

unread,
Sep 8, 2016, 9:00:03 PM9/8/16
to webdriver
use <WebElement>.getAttribute("value") to extract text

On Wednesday, January 9, 2013 at 3:51:25 AM UTC+5:30, BillR wrote:
I am finding that WebElement.getText() returns an empty string sometimes, but when it happens and I take a screenshot, the text is there. When I getAttribute("class") I see that I have found the right element, but it doesn't give me the text. Not sure if this would be a webdriver of FF bug. (A parent div has 'active' appended to its class when the popup containing the text appears, and this seems reliable.)

Has anyone seen this sort of thing? I see it running 1 test thread as well as >1.

Thanks,
Bill

FF 17.0
selenium-server-standalone-2.28.0.jar
Ubuntu with Xvfb

Html:

<div id="summaryTip" class="xpop xtip size-medium useCloseBox xpop-position-bottom active" style="width: 275px; top: 305px; left: 738px; z-index: 20;">
  <div class="xpop-content-container">
    <a class="xpop-close">x</a>
    <div class="xpop-title"></div>
    <div class="xpop-content">You will see a summary of your transfer as you proceed. </div>
  </div>
  <div class="xpop-pointer" ...</div>
</div>

Code:

    @FindBy(id = "summaryTip")
    WebElement receiptSummaryHolder;
    //@FindBy(xpath = "//div[@id='summaryTip']/div/div[2]")
    @FindBy(css = "#summaryTip .xpop-content")
    WebElement receiptSummaryTip;
    boolean receiptSummaryTipActive() {
        String s = receiptSummaryHolder.getAttribute("class");
        System.out.println("### summaryTip class: " + s);
        return s.contains("active");
    }
    String getReceiptSummaryTip() {

        String s = receiptSummaryTip.getText();
        if (s == null  ||  s.trim().length() == 0) {
            System.out.println("### empty, class = " + receiptSummaryTip.getAttribute("class"));
            WebElement we = receiptSummaryHolder.findElement(By.className("xpop-content"));
            System.out.println("### by.class [" + we.getText() + "] [" + we.getAttribute("class") + "]");
            return we.getText();
        }
        System.out.println("### NOT EMPTY: [" + s + "]");
        return s;
    }

Output:

    ### empty, class = xpop-content
    ### by.class [] [xpop-content]
    Screenshot: screenshots/1357682907182_8_no_rcpt_summary_1.png [shows text]
    ### empty, class = xpop-content
    ### by.class [] [xpop-content]
    ### summaryTip class: xpop xtip size-medium useCloseBox xpop-position-bottom active



Reply all
Reply to author
Forward
0 new messages