Is there any easy / automated way to scroll down in a page using RSelenium?
I use a delay in a page in which I should scroll down to see the content.
remDr$navigate("http://www.pageyouprefer.com/")
Sys.sleep(35)
You can scroll by javascript execute.
Try this one.
WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,200)", "");
Related
Scenario:
Launch http://www.indiabookstore.net/.
Click on FB like button which is inside an iframe. (scroll down to see it)
Issue:
I'm able to switch to the iframe, but couldn't click on the button, as there is a NoSuchElementException
I tried giving relative as well as absolute xpaths, didn't work.
Try out this way...
driver.switchTo().frame(
driver.findElements(By.tagName("iframe")).get(2));
new WebDriverWait(driver, 20).until(
ExpectedConditions.elementToBeClickable(By
.xpath("(//span[.='Like'])[1]"))).click();
I tried couple of times executing through WebDriver, but facebook like button is not coming up. So i tried for Twitter with below code, which worked for me.
WebDriver driver = new FirefoxDriver();
driver.get("http://www.indiabookstore.net/");
Thread.sleep(10000);
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#class='home-twitter']")));
driver.findElement(By.xpath("//span[#class='label']")).click();
Watch the above said video else watch this video to know more about switch between frames: https://www.youtube.com/watch?v=yYv_7-zYz4k
The following code should work for fb Like button:
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.indiabookstore.net/");
driver.switchTo().frame(driver.findElement(By.xpath("//html/body/div[1]/div[11]/div[1]/div[2]/div[1]/div/span/iframe")));
WebElement fb = driver.findElement(By.xpath("//html/body/div/div/div/table/tbody/tr/td[1]/div/form/div/div[1]"));//fb Like button
Actions builder = new Actions(driver);
builder.moveToElement(fb).click().build().perform();
driver.switchTo().defaultContent();
I'm testing our website login sequence with selenium. When I click login it loads an iframe, and the iframe id value changes each time it is loaded. So the test case fails in selenium.
What is the the command to read only the dynamic part of the iframe and locate it during the test run?
try this for capturing the popup,
String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.
WebDriver popup = null;
Iterator<String> windowIterator = browser.getWindowHandles();
while(windowIterator.hasNext()) {
String windowHandle = windowIterator.next();
popup = browser.switchTo().window(windowHandle);
}
Hope it will helpful to you
Use FrameIndex to switch iframes.
driver.switchTo().frame(1);
or use xpath
driver.switchTo().frame(webElement)
Or share Html Code so we can give a better solution.
I am using Selenium Webdriver (the 2nd) in java
I am trying to figure out how to type inside of an IFrame. Right now, I am:
WebDriver driver = new FirefoxDriver();
Wait<WebDriver> wait = new WebDriverWait(driver, 30)
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#cke_contents_textarea1 iframe"))).sendKeys("Test Text");
The html is:
<td id="cke_contents_textarea1" class="cke_contents" style="height:200px" role="presentation"><iframe style="width: 657px; height: 100%; " frameborder="0" title="Rich text editor, textarea1, press ALT 0 for help." src="" tabindex="-1" allowtransparency="true">
</iframe>
</td>
I've edited a lot of code out, so I might of missed pasting something in.
I have verified that the cursor appears inside of the text box (and when I select a different iframe, the cursor moves as well)
Is there different code to type in an Iframe?
Please refer sample code: I have used website contains iFrame.
(Note: you have to make sure in our webpage source code contain(s) iframe)
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.packagemapping.com/example1.htm#.UJS4DFIerb8");
driver.switchTo().frame(driver.findElement(By.name("frame_track")));
System.out.println(driver.findElement(By.xpath("//*[#id='table2']/tbody/tr/td[3]/font")).getText());
driver.findElement(By.name("shipper")).sendKeys("DHL");
I am surprised you see the cursor without switching to the Iframe.
Try doing it this way
driver.switchTo().frame(driver.findElement(By.id("frameId")));
//do your stuff
driver.switchTo().defaultContent();
for typing inside the iframe use the following Java code for selenium Webdriver.
driver.switchTo().frame((WebElement)driver.findElement(By.xpath("enter xpath of iframe here")));
driver.findElement(By.xpath("xpath of iframe textbox")).sendKeys("testing");
driver.switchTo().defaultContent();
It happens because the element is not fully loaded.In my case putting Thread.sleep(1000) before sendKeys did the trick.
WebElement iFrameElmnt = cntntPnlFrmWrpr.findElement(By.tagName("iframe"));
driver.switchTo().frame(iFrameElmnt);
WebElement inputText = driver.findElement(By.id("__o3id0"));
Thread.sleep(1000);
inputText.sendKeys("12344");
I want to redirect a new tab and to get focus of the new window when a button is clicked.. I can create a new window, but can't get its focus even thourh, I tried the following code
Window.focus(); How to do this?
My Code:
function new_window(url)
{
//Open a Window in New tab
var popupwin = null;
popupwin = window.open(url);
popupwin.focus();
self.focus();
//window.focus();
}
I think it would be better not to do this. These are browser preferences and don't try to override those. It may fail due to user settings.
Remove
self.focus();
You can use focus() method of a form element. This brings mostly the window to front. window.focus() might implemented different by different browsers.
Do you have html input elements on you popup win?
Try calling focus() on one of the html input elements. This will place the cursor into the element to assist the user start typing there.
All I need to open a new IE Window from within Flex code on click of a link.
P.S I dont want to open a new Browser. I want to open a browser window only that can open a new URL.
Something like clicking on a link in Flex and then open cnnibn.com in a Pop up window.
You should just be able to use:
navigateToURL(new URLRequest('http://www.cnnibn.com'), '_blank');
(make sure you import the relevant packages: "import flash.net.*")
This approach may have issues with some popup blockers, if so then you could have a look at the class here:
http://www.zorked.com/flash/flash-and-navigatetourl-popup-blocking/
One of the following methods will work unless the popup blocker blocks it.
Use navigateToURL
Add the following to the click handler of the button
navigateToURL(new URLRequest("cnnibn.com"), "_blank");
Use ExternalInterface
Add this line to click handler
ExternalInterface.call("openPopup", "cnnibn.com");
And the following to a script tag in the embedding html page
function openPopup(url)
{
window.open(url, "_blank");
}