We can scroll the page by using FOCUS command...
Below is the example...
package reporting;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
public class Focus extends SeleneseTestCase {
public SeleniumServer aa;
@Before
public void setUp() throws Exception {
aa= new SeleniumServer();
aa.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");
selenium.start();
}
@Test
public void testFocus() throws Exception {
selenium.open("/");
selenium.windowMaximize();
selenium.type("q", "selenium wiki");
selenium.click("btnG");
//Waiting for an element
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.isElementPresent("link=Selenium Overview - Wiki - Liferay.com")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
//Set focus on element --then page will scroll down --focus will be on that element
selenium.focus("link=Selenium Overview - Wiki - Liferay.com");
//To capture a screenshot
selenium.captureScreenshot("c:/naga/screenshot.png");
Thread.sleep(10000);
}
@After
public void tearDown() throws Exception {
selenium.stop();
aa.stop();
}
}
- focus(locator)
- Arguments:
- locator - an element locator
- Basically there is no specific command for scrolling the page down. I tried keyPress and all other options, but i felt Focus is the best for scrolling the page down. We need to select a element and set focus on that element.
Below is the example...
package reporting;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
public class Focus extends SeleneseTestCase {
public SeleniumServer aa;
@Before
public void setUp() throws Exception {
aa= new SeleniumServer();
aa.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");
selenium.start();
}
@Test
public void testFocus() throws Exception {
selenium.open("/");
selenium.windowMaximize();
selenium.type("q", "selenium wiki");
selenium.click("btnG");
//Waiting for an element
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.isElementPresent("link=Selenium Overview - Wiki - Liferay.com")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
//Set focus on element --then page will scroll down --focus will be on that element
selenium.focus("link=Selenium Overview - Wiki - Liferay.com");
//To capture a screenshot
selenium.captureScreenshot("c:/naga/screenshot.png");
Thread.sleep(10000);
}
@After
public void tearDown() throws Exception {
selenium.stop();
aa.stop();
}
}
How to do this in Selenium IDE ?
ReplyDeleteI tried Focus, KeyDown, KeyPress in Selenium IDE. But didn't work.
Hello there! I just wish to give you a big thumbs up for the great information you have got right here
ReplyDeleteon this post. I am returning to your website for more soon.
My website :: ideal waist to hip ratio
Also see my page: waist to hip ratio calculator
2018425 leilei3915
ReplyDeletecoach outlet
fitflop sale
ray ban sunglasses wholesale
canada goose
gucci outlet
fitflops sale clearance
cheap ray ban
michael kors outlet clearance
pandora charms
adidas superstar
michael kors outlet online
ReplyDeletefred perry clothing
coach outlet online
coach outlet
michael kors outlet clearance
coach outlet
true religion outlet store
uggs outlet
coach outlet online
supreme hoodie
chenminghui2018427
converse outlet
ReplyDeletebalenciaga sneakers
kyrie 5
moncler
converse shoes
louboutin outlet
hermes belt
louboutin
outlet golden goose
retro jordans