-1

I tried to using absolute xpath to locate the dynamic text field element after search but it fails.

<div class="pzbtn-rgt" data-click="...">
<div class="pzbtn-mid" data-click="....">
<img src="https://10.204.137.86:5111/prweb/PRWebLDAP3/SstGGrXNazw%5B*/webwb/zblankimage.gif" alt="" class="pzbtn-i">
Create Individual CID
<img alt="" src="https://10.204.137.86:5111/prweb/PRWebLDAP3/SstGGrXNazw%5B*/webwb/zblankimage.gif" class="pzbtn-i">

The Create individual CID is the one with dynamic action. I tried with many ways but still doesn't works. Please help. Thanks.

  • 2
    Where is your text field in the given code? there are only <img> tag. – Upkar Singh Apr 2 at 4:41
0

As Upkar mentioned, we cannot determine exactly the problem. But most probably you will need to include an explicit wait for a condition where your test can proceed.

new WebDriverWait(10 /*seconds*/).until(
    ExpectedConditions.visibilityOfElementLocated(By.css(XXX)
));

You can find more about Expected Conditions here.

0

I can only offer 2 thoughts.

  1. It might be a design issue if the dynamic text isn't wrapped itself by anything that doesn't wrap its peer elements.
  2. You might be able to get there by using some of the special parts of CSS https://www.tutorialspoint.com/css/css_syntax.htm Shows you how to look for descendents:

Imagine you had a dialog structured like this:

<div class="container">

    <div class="dialog">
        <div class="dialog-header">
            <img class="dialog-icon" src="../someicon.ico" />
            <div class="dialog-title">My Dialog Title</div>
        </div>
        <div class="dialog-body">
            <div class="randomclass"> 1. random text 1</div>
            <div class="randomclass-2"> 2. random text 2</div>
            <div class="randomclass-2"> 6. random text 6</div>
            <img class="random-image-3" src="../randominage3.png" />
            4. Stand Alone Text
            <img class="random-image-5" src="../randomimage5.gif" />
        </div>
        <div class="randomclass-2"> 7. random text 6</div>

        <div class="dialog footer">
            ... some footer stuff here ...
        </div>
    </div>

</div>

You might be able to get at the second line of text (2.) with the following CSS which you can test in the Chrome Dev Tools Console with the following command (the part in single quotes is the CSS selector)

$$('div div.dialog-body div.randomclass-2'); or possibly with just 'div.dialog-body > div.randomclass-2'. The > operator means it will only pick up on decendents. (SO it might get both of the randomclass-2 divs inside dialog-body, but not the one that's between the dialog-body and footer. to get at that one, you could try by changing the > to a plus sign which is the sibling locator. However, how would you get at 4.? I don't believe its possible in CSS3 even. SeleniumIDE had some javascript to help with text lookup, but it had a flaw, that it would scrape all text, not just 4. (meaning any text contained might get scrapped.) I'd suggest to devs that the put a wrapper element (div or span, around the dynamic text) in order to make it easier to grab and text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.