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");
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 search too much on Google but i couldn't find any result so i'm posting my question here
I'm using wordpress 3.6 and the wp e-commere plugin
i'm use this anchor tag
<a target="_blank" href="http://www.google.com">google</a>
i also use window.open(url,'_blank'); // function do same problem
when a user clicks on the link, a new tab opens and within 1 second it closes again.. its not working in mozilla and chrome, but it is working in IE
i checked and there is no theme problem.
if i add an anchor tag from e-commerce product then the tag target=_blank will not work, and if i add a anchor tag from wp product then the anchor tag will work...
How can i solve this problem?
and if i add href value with out http:// e.g
google
it opens in new tab successfully
but then its url is
localhost/wordpress/product/www.google.com
if i write a proper href with http://, so there is open and close issue.
Any one know it solution ?
i apply many type of jquery and javascript code, but actually when i write _blank, and then new tab opening then issue comes
Update:
i'm adding some javascript code,
i use this method to open new tab
function urltarget(url,target){
if (target == '') {
target = '_self';
}
window.open(url,target);
return false;
}
if i enter
<a href="" onclik="urltarget('http://www.example.com','_blank');" > Example </a>
//its work ok, but if i used .net url
<a href="" onclik="urltarget('http://www.example.net','_blank');" > Example </a>
//when .net comes in url then it create problem, new tab open and again close.
but it work in IE
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 have an iframe that gets loaded when i click on a tab on a page. When i use Firebug to look at the iframe on IE8, all i see is:
iframe id=tabContextFrame class=contextFrame contentEditable=inherit src=/xyz.dt?forward=show&layouttype=NoHeader&runid=1234 name=tabContextFrame url=/xyz.dt?forward=show&layouttype=NoHeader&runid=1234 scrolling=auto
and that's it.The hierarchy below the iframe can't be seen. I want to click on a link within the iframe. To find the elements within the iframe, I did a selenium.click("on the tab that loads the iframe") and then selenium.getHtmlSource(). From this source, I can at least locate my link of interest. I did a selenium.click("//span[text()='Link']") but it doesn't seem to do anything. Any ideas please?
Here is the code:
selenium.click("//span[text()='tab that loads iframe']");
Thread.sleep(5000);
selenium.selectFrame("tabContextFrame");
selenium.mouseOver("//span[text()='Link']");
selenium.mouseDown("//span[text()='Link']");
selenium.mouseUp("//span[text()='Link']");
Thread.sleep(5000);
selenium.selectFrame("null");
I'm guessing you are using Selenium 1.0. Have you looked at Selenium 2.0 and WebDriver. I found the following and it worked for me:
Q: How do I type into a contentEditable iframe? A: Assuming that the
iframe is named "foo":
driver.switchTo().frame("foo");
WebElement editable = driver.switchTo().activeElement();
editable.sendKeys("Your text here");
Sometimes this doesn't work, and this is because the iframe
doesn't have any content. On Firefox you can execute the following
before "sendKeys":
((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<br>'");
This is needed because the iframe has no content by default:
there's nothing to send keyboard input to. This method call inserts an
empty tag, which sets everything up nicely.
Remember to switch out of the frame once you're done (as all further
interactions will be with this specific frame):
driver.switchTo().defaultContent();
I found this on http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
Use driver.switchTo().defaultContent(); first then do your operation
Is there a way to open a page in XHTML without using <a href="page.html" target="_blank"> that is standards compliant?
I'm not using frames, but there are some pages that I want to open in a new window instead of the current one.
You can use javascript's window.open() method. However this could easily be blocked by a pop-up blocker. Why do you not want to use the "_blank" target?
You can use something like this:
My Page
And then you run this jQuery:
$(document).ready(function() {
$('a[rel="external"]').attr('target', '_blank');
});
This will add the target="blank" to the links and make your HTML validate :)
Most pop-up blockers wont block a pop up that has been requested by the user e.g you click a link and it pops up a window. IF you add an onlick event to your link and a target, the desired effect will work even if JS is turned off although you don't want to use target="_blank"