18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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 set javascript to browser using sahi
Hi all,
I am using browser.setBrowserJS() for injecting java script, but its not working. can anybody tell me how need to use this method.
I am using browser.setBrowserJS() for injecting java script, but its not working. can anybody tell me how need to use this method.
Comments
The documentation on how to use browser.setBrowserJS() is available in the following link.
http://sahi.co.in/java/javadocs/net/sf/sahi/client/Browser.html#setBrowserJS(java.lang.String)
Use the same syntax.
Let us know if the problem persists.
Regards
Theeran.
I have gone through the link which you have sent, but passing the below code is not working and its not giving any error.
browser.setBrowserJS("document.getelementbyId()........");
Note:I have created some sample javascript application and trying to automated all the elements in that from my sahi code.
Try the following script to use browser.setBrowserJS,
you should see the value of the element to be displayed in the console.
let us know it the problem persists.
Regards
Theeran.
This is my sahi code
browser = new Browser("firefox");
browser.open();
browser.navigateTo("http://www.eviltester.com/selenium/basic_ajax.html"
System.out.println("thomson");
browser.setBrowserJS("function value(){return document.getElementById('lteq30').value;}");
System.out.println(browser.fetch("value()"));
This is the error stacktrace i am getting while running the above code:
Exception in thread "main" error:_sahi.setServerVarPlain('___lastValue___Thu Nov 10 14:01:14 IST 2011', value())
ReferenceError: value is not defined
http://www.eviltester.com/_s_/spr/concat.js:3016
http://www.eviltester.com/_s_/spr/concat.js:3016
http://www.eviltester.com/_s_/spr/concat.js:2822
<a href='/_s_/dyn/Log_getBrowserScript?href=null&n=3016'><b>Click for browser script</b></a>
at net.sf.sahi.client.Browser.executeStep(Browser.java:223)
at net.sf.sahi.client.Browser.execute(Browser.java:190)
at net.sf.sahi.client.Browser.fetch(Browser.java:478)
at org.sonata.TestJS.main(TestJS.java:26)
Ensure that the element HAS a value attribute. It looks like there isn't one. If you want to get the text inside the tag, try
For IE,
let us know if the problem persists.
Regards
Theeran.
As the code mentioned below I am able to execute javascript using selenium
driver.get("http://www.eviltester.com/selenium/basic_ajax.html"
JavascriptExecutor js = (JavascriptExecutor) driver;
String script ="document.getElementById('lteq30').value=24;"; //This is for the textbox
js.executeScript(script);
If i am using the same code for sahi(as mentioned below) its not working
browser.setBrowserJS("document.getElementById('lteq30').value=24;");
May i know what is the issue