18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Regexp in a _div( texte+number )

Fabrice BFabrice B Members
edited November -1 in Sahi - Open Source
Hi all,

I made a search on all topics which talk about regexp but all my tries are on error

my case :

i've a _div composed by a text and a number between parenthesis like this

=> _div("Eric Besson (2)")

To test, i made : _highlight( _div("Eric Besson (2)") ); => it's ok

The number between parenthesis is never the same, so i try to put this number in a regexp [0-9]+
=> all my tries are on error


anybody could help me for this regexp syntaxe please ?

Thx

regards

Fabrice B

Comments

  • mohanmohan Members
    Hi Fabrice B

    use _near ,_in,_under Api's

    http://sahi.co.in/w/sahi-api-examples
  • mohan wrote:
    Hi Fabrice B

    use _near ,_in,_under Api's

    http://sahi.co.in/w/sahi-api-examples


    Hi,

    So sorry, but i dont see the link with regexp ?

    Thank you

    Regards

    Fabrice B
  • mohanmohan Members
    edited July 2011
    Hi Fabrice

    its look like Indexing issue. regular expression not helpful for you in this scenario. please check in your page the same name is repeated somewhere that will be Eric Besson ,the second index is Eric Besson (1),third one is Eric Besson (2) .Sahi indexes the same text like this format. you have to use _near, under Api please check the same in the above url.
  • Fabrice BFabrice B Members
    edited July 2011
    Hi Mohan,

    No i'm sorry i ve not be explicit enough

    In fact i have a list of names followed by ("a number"), but i ve the name just one time, the number is only a count : i give you a part of innerHTML of my page
    <div id="gwt-uid-12" role="treeitem" class="gwt-TreeItem" style="display: inline;">Person</div>
    </td>
    </tr>
    </tbody>
    </table>
    <div style="white-space: nowrap;">
    <div style="padding: 3px 3px 3px 13px; margin-left: 16px;">
    <div id="gwt-uid-13" role="treeitem" class="gwt-TreeItem" style="display: inline;">Eric Besson (2)</div>
    </div>
    <div style="padding: 3px 3px 3px 13px; margin-left: 16px;">
    <div id="gwt-uid-14" role="treeitem" class="gwt-TreeItem" style="display: inline;">Nathalie Kosciusko-Morizet (2)</div>
    </div>
    <div style="padding: 3px 3px 3px 13px; margin-left: 16px;">
    <div id="gwt-uid-15" role="treeitem" class="gwt-TreeItem" style="display: inline;">Benoît Hamon (1)</div>
    </div>
    <div style="padding: 3px 3px 3px 13px; margin-left: 16px;">
    <div id="gwt-uid-16" role="treeitem" class="gwt-TreeItem" style="display: inline;">Benoît Hamon, porte-parole (1)</div>
    </div>


    sahi recorder gives me : _div("Eric Besson (2)") : Great ! it's i prefer click on a explicit name instead of a gwtId,
    So, i need to click on this _div, but the number between parenthesis is a count which change every time, every click change this count. So (again), i thought : if i use a regexp [0-9]+ i can click my _div without have to known the number...


    Maybe it's not the right method ... What do you think of this?

    Thank you for the time spent

    Regards

    Fabrice B
  • SumitraSumitra Members
    Hi Fabrice B,

    You can try using this:

    _div("/^Eric Besson \(/");

    Let me know if this solves your issue.

    Regards
    Sumitra
  • Fabrice BFabrice B Members
    edited July 2011
    Hello Sumitra,

    Sorry for the delay...

    Sorry too for the solution, i obtained

    _highlight( _div("/^Eric Besson \(([0-9]+)\)/") );
    TypeError: el is undefined

    and

    _highlight( _div("/^Eric Besson \(/")) );
    SyntaxError: missing ; before statement


    Do you see another method than a regexp to do that ?

    Regards

    Fabrice B
  • Fabrice BFabrice B Members
    edited July 2011
    It's OK, i found, it was so simple again...

    Sumitra, You gave me idea... the parenthesis are the problem, but i dont need the parenthesis

    _highlight( _div("/Eric Besson .*/") );


    It's OK, Thank You

    Thank you all for your searches

    Fabrice B
This discussion has been closed.