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();
Related
How to run same page in browser, when I stopping and re running a page its displaying in new tab and i don't want to display in new tab and I want to display in same page and I'm working on windows form application in c# .net.
Can u please suggest me any one.
The below code I have written like this way.
Process.Start("microsoft-edge:http://www.google.com");
Process[] Edge = Process.GetProcessesByName("MicrosoftEdge");
foreach (Process Item in Edge)
{
try
{
Item.Kill();
Item.WaitForExit(100);
}
catch (Exception)
{
}
}.
Based on my research, I could not find a way to use Process to display the same page in the Edge.
However, I find a alternative method to do it.
First, please install nuget-package Selenium.WebDriver and Selenium.WebDriver.MSEdgeDriver.
Second, please copy the msedgedriver.exe from the packages (path:packages\Selenium.WebDriver.MSEdgeDriver.91.0.864.37\driver\win64)to the bin\debug folder and rename it to MicrosoftWebDriver.exe
Finally, you could try the following code to open the Google page to replace the Bing Page in the same tab:
var driver = new EdgeDriver();
// Navigate to Bing
driver.Url = "https://www.bing.com/";
driver.Navigate();
// Navigate to Google
driver.Url = "https://www.google.com/";
driver.Navigate();
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)", "");
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.
We are testing an application with Selenium WebDriver. HTMLUnitDriver is our choice (because of non-gui-testing) and sometimes IEDriver for Presentationpurposes. Anyway, i try to perform a click on a button, this one has to open an rich:popuPanel(modal=true) and click a Link on that Panel. With IEDriver that's no problem, but with HTMLUnitDriver the popupPanel doesn't open. I tried to perform these clicks in several ways:
JavascriptExecutor jsdriver = (JavascriptExecutor) driver;
jsdriver.executeScript("$('input[id$=freigabeCmd_id]').focus();");
//below are the other tries
// jsdriver.executeScript("$('input[id$=freigabeCmd_id]').click();");
// jsdriver.executeScript("window.document.getElementById('editorViewForm_id:freigabeCmd_id').click()");
// jsdriver.executeScript("arguments[0].click()", freigabeButton);
// jsdriver.executeScript("arguments[0].fireEvent('onclick');", freigabeButton);
further i tried it the "normal way":
freigabeButton.click();
//below are other ways i found here on stackoverflow
// freigabeButton.sendKeys(Keys.ENTER);
// new Actions(driver).moveToElement(freigabeButton).clickAndHold().release().build().perform();
but nothing brought me to get the popupPanel "visible". Anyone got an idea why?! i'm really stuck right now. If you need more Informations pls let me know.
using: HTMLUnit Version 2.12 and latest SeleniumVersion
It might be that your webapp uses javascript to launch the rich pop-up panel, and you are running HtmlUnitDriver with javascript disabled? It is disabled by default, so you need to explicitly enable it.
I'm using Webdriver to test my web application. When I work with FireFoxDriver or ChromeDriver everything seems to be ok. When I work with HtmlUnitDriver though things start to go wrong.
Here is a sample code:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://localhost:8099/");
WebElement loginButton = driver.findElement(By.xpath("//button[#type='button']"));
loginButton.click();
i'v looked at the driver.getPageSource result, and the source code presented there is very partial.
it doesnt show me all the elements. it is the same a clicking view source on the page.
what i need from the driver is the entire source, like firebug or chrome inspector give me.
any ideas on how i can retrieve it?
my app was written with the GWT.
thanks a million
Have you tried to enable JavaScript for HtmlUnitDriver?
I believe that the HTMLUnitDriver emulates IE by default (link) and there are other questions related to clicking buttons with IE. Have you tried this?
// Press enter on the button
loginButton.sendKeys("\n");
Also, have you tried adding an ID to the element and using that to find the button?