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.

How to click first link on a page, if links on that page is not static

TinaTina Members
edited November -1 in Sahi - Open Source
Hi,
I am unable to write the script for 'clicking the first link on the page, if the link is not static (means the links of that webpage keeps on changing on a daily basis. So how to write a script for it ?

Comments

  • TinaTina Members
    I have written this function for the same:

    function getFirstLink(){
    var list = document.getElementById("recipe-teaser");
    var li = list.getElementsByTagName("li");
    var aText = li[0].getElementsByTagName("a")[1].innerHTML;

    _click(_link(aText));
    }

    but i am getting following error on execution:
    _click(_link(aText));
    TypeError: 'aText' is undefined
    No trace available


    Kindly suggest solution for this.

    Regards,
    Tina
  • narayannarayan Administrators
    The first link is

    _link(0)

    If you want a first link inside "recipe-teaser", use

    _link(0, _in(_byId("recipe-teaser")))
  • TinaTina Members
    Thanks for the code.

    Also, i want to know why is my code not working. Can you please tell me.

    Regards,
    Tina
  • TinaTina Members
    If id is not given and div class is there then how to click the first link?

    please reply, i am stuck in between

    Regards,
    Tina
  • narayannarayan Administrators
    Use something like:

    _link(0, _in(_div("class_name")))

    Check out "Using custom functions that access the DOM." in http://sahi.co.in/w/sahi-script-and-javascript to understand how to write the code that you had initially posted.

    Regards,
    Narayan
  • TinaTina Members
    Hi,

    I am facing a problem while running my suite script from command prompt :

    Connection refused: connect
    Could not connect to Sahi Proxy.
    Verify that the Sahi Proxy is running on the specified host and port.

    Please help me asap.

    Regards,
    Tina
  • TinaTina Members
    Also i have written the proxy host and port.
    Still i am facing this problem.
  • SumitraSumitra Members
    Hi Tina,

    Please create a new forum post.

    You have to start Sahi before running your suite script.

    Regards
    Sumitra
  • TinaTina Members
    Hi Sumitra,

    I am unable to create a new post. :(

    Also i tried what you said, but i am again facing Failure.

    please suggest what to do.

    Regards,
    Tina
  • TinaTina Members
    Actually the url which i have provided opens for not more than 2sec. And i get Failure message on the command prompt.

    Regards,
    Tina
  • TinaTina Members
    Hi Sumitra,

    I am getting what i want. :)
    Thanks for your help.

    Also can you please tell me how to create a new post, because there's only option for creating a message. Is message or post same thing?
    Please reply because i have more questions to ask.

    Regards,
    Tina
  • SumitraSumitra Members
    Hi Tina,

    You can create a new post by Clicking on Post new topic on the forum page.

    Regards
    Sumitra
  • Could you provide script for clicking the first link on the page of a popup window, if the link is not static (means the links of that webpage keeps on changing on a daily basis.)?
Sign In or Register to comment.