This is for an iframe injected into Gmail, I am unable to switch to this frame any help is highly appreciated.
HTML Code:
<iframe src="chrome-extension://fcinnggknmdfkilogcndkgpojpfojeem/src/iframe.html" id="Hiver_iframe_content" style="width: 100%; height: 263px; position: absolute; top: 60px; z-index: 4; border: none; display: none;"></iframe>
What I am trying to do :
driver.switchTo().frame("Hiver_iframe_content");
used to work perfectly fine a few days back..!!
This is not the way of switching frame what you are trying like
driver.switchTo().frame("Hiver_iframe_content");
You have to pass webElement or Index of frame while switching
Try this and let me know
driver.switchTo().frame(driver.findElement(By.id("Hiver_iframe_content")));
OR
driver.switchTo().frame(0); // 0 is index of frame
You can wait for the frame to load using explicit wait as given below.
WebDriverWait wait=new WebDriverWait(driver, 90);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("Hiver_iframe_conten"));
Try and let me know.
Thanks,
Murthi. S
try using switching to frame WebElement as below:
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe#Hiver_iframe_content")));
Appears that along with the release of New login for Gmail google released a new version of chrome driver , i fixed my issue by upgrading my chromedriver version
I found a way to switch to iframe which you mentioned. As a matter of fact there is not a single iframe but two iframes you have to switch. see the code below:
driver.switchTo().defaultContent();//First switch to default content
driver.switchTo().frame("Hiver_iframe_content");//Switch to 1st iframe
driver.switchTo().frame("iframe_handler");//Switch to 2nd iframe
P.s-This code now works for our automation and we're able to access v2 from iframe itself :-)
Related
I want to show a WebPage on another WebPage using InlineFrame.
I initialized it like this:
Wicket/ Java:
InlineFrame choosenTestcaseInlineFrame =
new InlineFrame("inlineFrame", AuthenticationPage.class);
public WhatToDoPage() {
Form whatToDoForm = configureWhatToDoForm();
add(whatToDoForm);
add(choosenTestcaseInlineFrame.setOutputMarkupId(true));
add(choosenTestcaseInlineFrame);
}
'
HTML:
<iframe wicket:id="inlineFrame" style="margin-left: 200px; height: 500px; width: 1000px">
The Problem is That the InlineFrame seems to refuse to show the Content.
here is a Screenshot:
I don't know if Chrome has a specific option to allow iframe to be displayed, but you might find some clues to solve the problem here:
iframe refuses to display
I am learning to automate procress in a website. I chose http://logos.iti.gr/logos/ as a website to automate. I am facing a problem when uploading the image file using the upload an image button because this button when clicked seems to convert into a text field.
The other tutorials I followed get the id of the text field and use sendkeys to send the path because they do have separate text field and upload button key.
Here is the code that I tried :
driver.get("http://logos.iti.gr/logos/");
driver.findElement(By.id("fileToUpload")).clear();
System.out.println("Cleared");
driver.findElement(By.id("fileToUpload")).sendKeys("/home/test.jpg");
I don't know what the problem is. It just get IPDL protocol error: Handler returned error code!
org.openqa.selenium.ElementNotInteractableException: Element <input id="fileToUpload" class="input_file" name="fileToUpload" type="file"> could not be scrolled into view
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16'
You get ElementNotInteractableException - it is thrown to indicate that although an element is present on the DOM, it is not in a state that can be interacted with. In your case it happens because the element has style display:none. Basically, selenium (and real users as well) can't interact with non-visible elements. You need to make element visible at the frist place and then continue.
driver.get("http://logos.iti.gr/logos/");
WebElement el = driver.findElement(By.id("fileToUpload"));
System.out.println("Making element visible");
((JavascriptExecutor)driver).executeScript("arguments[0].style.display = 'block';", el);
el.clear();
System.out.println("Cleared");
el.sendKeys("/home/test.jpg");
By the way here is the default element style (you can see it in browser dev tools). Pay attention to display:none. When you change the value to block don't be confused that you actually don't see any changes on a screen because element's width and height are very small.
.input_file {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
display: none;
}
Try updating your client and Firefox. Hopefully that should solve this issue.
I have never faced any issue with file uploads until the webpage mandates the dialog box while clicking the image upload. I am using latest version of ChromeDriver and Chrome.
If possible, you too switch to ChromeDriver since I find the pair working seamlessly together in my experience! :)
I am currently testing a GWT web application similar to MS Paint and the problem which I am facing is that my test case passes on the browsers like Chrome, Firefox, and IE but sadly, it fails in the Microsoft Edge browser. I am unable to find out how to fix this issue after searching the whole Internet and trying out many methods which are written on the Stack Overflow and Google Groups, I am feeling extremely hopeless. Meanwhile, here is my code:
public class Insert_Element_in_Edge {
private static WebDriver driver;
#Test
public void main() throws InterruptedException, IOException
{
// TODO Auto-generated method stub
System.setProperty("webdriver.edge.driver", "D:\\SELENIUM\\Drivers\\MicrosoftWebDriver.exe");
driver = new EdgeDriver();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.manage().window().maximize();
Thread.sleep(3000);
driver.get("xxxx.com");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.titleContains("xxxx"));
WebElement canvas = driver.findElement(By.id("frontCanvas"));
Thread.sleep(3000);
final String InsertPath="//img[contains(#src,'Insert Element')]";
WebElement Insert = driver.findElement(By.xpath(InsertPath));
Thread.sleep(3000);
Insert.click();
}
}
Here's the error which I am facing:
org.openqa.selenium.ElementNotVisibleException: Element not displayed (WARNING: The server did not provide any stacktrace information)
Given below is the HTML code of the element which I am trying to locate in the Edge browser.
<div id="isc_2Q" eventproxy="isc_XXXIconButton_SClient_1" role="button" aria-label="xxx"
onfocus="isc.EH.handleFocus(isc_XXXIconButton_SClient_1,true);"
onblur="if(window.isc)isc.EH.handleBlur(isc_XXXIconButton_SClient_1,true);"
tabindex="1020" style="position: absolute; left: 0px; top: 54px; width: 40px;
height: 34px; z-index: 201152; padding: 0px; opacity: 1; overflow: visible;
cursor: pointer;" onscroll="return isc_XXXIconButton_SClient_1.$lh()" class="iconHoverZindex">
<div id="isc_2R"
eventproxy="isc_XXXIconButton_SClient_1" style="position: relative;
-webkit-margin-collapse: separate separate; visibility: inherit;
z-index: 201152; padding: 0px; cursor: pointer;">
<table role="presentation" cellspacing="0" cellpadding="0" width="40px" height="34px">
<tbody>
<tr>
<td nowrap="true" class="iconButton" style="background-color:transparent;"
align="center" valign="middle" onfocus="isc_XXXIconButton_SClient_1.$47()">
<img src="Insert Element.png" width="24" height="24" align="TEXTTOPundefined"
class="iconButtonHIcon" eventpart="icon" border="0"
suppress="TRUE" draggable="true"/>
<span style="vertical-align:middle;align-content:center;"></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
This element is visible in other 3 browsers and is clicked successfully. But I just got stuck in Edge. Also, in Edge, the HTML5 canvas is also not displayed using Selenium. Please help.
You can add wait statement before click on it as given below.
wait.until(ExpectedConditions.ElementIsVisible(By.xpath(InsertPath)));
You have to use element to be clicable as it is a button
WebDriverWait wait = new WebDriverWait (driver, 50);
final String InsertPath="//img[contains(#src,'Insert Element')]";
WebElement Insert= wait.until(ExpectedConditions.elementToBeClickable(By.xpath(InsertPath)));
Insert.click();
In the past I aslo had some trouble location elements with xPath in Edge, GWT and Selenium
Sadly I didnt found a solution but a workaround:
We gave every Element an ID
for example:
panel.getElement().setId("panel-id");
and then used the ID-Locator to find the Element:
findElement(By.id("panel-id"))
I read answers to your question that should solve your problem.
But noone asked you (and you did not provide us, in your question) informations about the version of your MicrosoftWebDriver, Selenium, and Browser that are you using.
From Microsoft WebDriver download, are you using a version that should be supported from your browser?
From EdgeHTML issue tracker, I found only 2 issues (that are fixed) with key element ElementNotVisibleException.
In these cases I usually take a screenshot just before the line where exception occurs and save it somewhere to further investigation. Then I mostly have to add a scrollUp()/scrollToVisible() function before this line to fix the problem.
I would suggest a few tweaks in your code block as follows:
First of all we will try to get rid of all the Thread.sleep(n) calls.
Now, to address the reason for ElementNotVisibleException, we will scroll the element of our interest within the Viewport and then invoke click() method.
Your final code block will may look:
driver = new EdgeDriver();
driver.manage().window().maximize();
driver.get("xxxx.com");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.titleContains("xxxx"));
WebElement canvas = driver.findElement(By.id("frontCanvas"));
WebElement Insert = driver.findElement(By.xpath("//div[#id='isc_2R']//td/img[#class='iconButtonHIcon' and contains(#src,'Insert Element.png')]"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", Insert);
Insert.click();
Other than above suggestions,
Make sure that "Your Element" that you are looking for is physically visible in your Browser screen. Meaning, if element is not visible , user needs to scroll down in order to see it. Driver behaves similar. In order to prevent "ElementNotVisiable" exception make sure it is also visible on browser page
Try This,
Select elm = new Select(driver.findElement(By.Xpath("Your element's Absolute Xpath")));
//Thread.sleep(100);
elm.selectByValue("Dropdown Value which you want to select");
I've exactly the same problem with GWT. For any reason there's no way to call click directly.
Workaround that worked for me
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click()", element);
HTML code:
<div class="buttonBG">
<input type="button" onclick="window.location.href='?mod=eA&act=00001';" class="buttonGreen" value="TK">
<input type="button" onclick="ttoggle('carianDiv');" class="buttonGreen" value="CK">
</div>
Below is my java code, when I try with below code. Can I know whats wrong is in my selenium webdriver code:
driver.findElement(By.xpath("//input[#class='buttonGreen' and contains(#onclick, 'window.location.href='?mod=eA&act=00001')]")).click();
Try to search by value
driver.findElement(By.cssSelector("[value='TK']")).click();
And for what's wrong, you are searching for ?mod=eA&act=00001 when in the html its
?mod=eA&act=00001
Edit
Another solution is to insert the buttons to list and click by index:
List<WebElement> buttons = driver.findElements(By.className("buttonGreen"));
buttons.get(0).click();
You can also try using explicit wait
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[value='TK']")).click();
This will wait up to 10 seconds for the button to be visible before clicking on it. You can change the selector or time span.
Try using XPath instead of CSS
driver.find_element(By.XPATH, '//input[#onclick=\'window.location.href=\'?mod=eA&act=00001\';\']').click()
Edit
Here is the code to switch to iFrame,
driver.switchTo().frame("frame_name");
NOTE: After completing the operation inside the iframe, you have to again return back to the main window using the following command.
driver.switchTo().defaultContent();
<div>
<iframe id="cq-cf-frame ">
<iframe id="gen367">
<body spellcheck="false" id="CQrte" style="height: 255px; font-size: 12px; font-family:tahoma,arial,helvetica,sans-serif; background-image: url("/libs/cq/ui/widgets/themes/default/ext/form/text-bg.gif"); background-repeat: repeat-x; background-attachment: fixed;">
<p>4t43t4<br></p>
</body >
</iframe>
</iframe>
</div>
In this scenario there is an iframe under iframe. And I have to select the outer iframe to go to inner iframe and write in the body which is in the inner iframe.
Next, I have to come out from the inner iframe to outer iframe and click on OK button, (which is in the outer iframe).
Following is my code
/*Line 1 */ driver.switchTo().frame("cq-cf-frame");
/* 2 */ driver.findElement(By.css("#extdd-9 > div.tblRow > input.edititem").click();
/* 3 */ driver.switchTo().Frame("cq-gen379");
/* 4 */ driver.findElement(By.id("CQrte").sendKeys("Tnx");
/* 5 */ selenium.selectFrame("relative=up");
/* 6 */ driver.findElement(By.xpath("//button[text()='OK']")).click();
Following is my problem:
My test code is working fine up to line number 4 i.e. writing into the body, but I want to come out from inner to outer iframe it says that the element //button[text()='OK'] not found.
I tried with using index, parent, relative, but had no luck.
NOTE: If I don’t select the inner frame (cq-gen379). I'm able to click on the OK button.
In Webdriver, you should use driver.switchTo().defaultContent(); to get out of a frame.
You need to get out of all the frames first, then switch into outer frame again.
// between step 4 and step 5
// remove selenium.selectFrame("relative=up");
driver.switchTo().defaultContent(); // you are now outside both frames
driver.switchTo().frame("cq-cf-frame");
// now continue step 6
driver.findElement(By.xpath("//button[text()='OK']")).click();
You have to get back out of the Iframe with the following code:
driver.switchTo().frame(driver.findElement(By.id("frameId")));
//do your stuff
driver.switchTo().defaultContent();
You need to first find iframe. You can do so using following statement.
WebElement iFrame= driver.findElement(By.tagName("iframe"));
Then, you can swith to it using switchTo method on you WebDriver object.
driver.switchTo().frame(iFrame);
And to move back to the parent frame, you can either use switchTo().parentFrame() or if you want to get back to the main (or most parent) frame, you can use switchTo().defaultContent();.
driver.switchTo().parentFrame(); // to move back to parent frame
driver.switchTo().defaultContent(); // to move back to most parent or main frame
Hope it helps.
To get back to the parent frame, use:
driver.switchTo().parentFrame();
To get back to the first/main frame, use:
driver.switchTo().defaultContent();
WebDriver driver=new FirefoxDriver();
driver.get("http://www.java-examples.com/java-string-examples");
Thread.sleep(3000);
//Switch to nested frame
driver.switchTo().frame("aswift_2").switchTo().frame("google_ads_frame3");
Below approach of frame handling : When no id or name is given incase of nested frame
WebElement element =driver.findElement(By.xpath(".//*[#id='block-block19']//iframe"));
driver.switchTo().frame(element);
driver.findElement(By.xpath(".//[#id='carousel']/li/div/div[3]/a")).click();
Selenium Web Driver Handling Frames
It is impossible to click iframe directly through XPath since it is an iframe. First we have to switch to the frame and then we can click using xpath.
driver.switchTo().frame() has multiple overloads.
driver.switchTo().frame(name_or_id)
Here your iframe doesn't have id or name, so not for you.
driver.switchTo().frame(index)
This is the last option to choose, because using index is not stable enough as you could imagine. If this is your only iframe in the page, try driver.switchTo().frame(0)
driver.switchTo().frame(iframe_element)
The most common one. You locate your iframe like other elements, then pass it into the method.
driver.switchTo().defaultContent(); [parentFrame, defaultContent, frame]
// Based on index position:
int frameIndex = 0;
List<WebElement> listFrames = driver.findElements(By.tagName("iframe"));
System.out.println("list frames "+listFrames.size());
driver.switchTo().frame(listFrames.get( frameIndex ));
// XPath|CssPath Element:
WebElement frameCSSPath = driver.findElement(By.cssSelector("iframe[title='Fill Quote']"));
WebElement frameXPath = driver.findElement(By.xpath(".//iframe[1]"));
WebElement frameTag = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame( frameCSSPath ); // frameXPath, frameTag
driver.switchTo().frame("relative=up"); // focus to parent frame.
driver.switchTo().defaultContent(); // move to the most parent or main frame
// For alert's
Alert alert = driver.switchTo().alert(); // Switch to alert pop-up
alert.accept();
alert.dismiss();
XML Test:
<html>
<IFame id='1'>... parentFrame() « context remains unchanged. <IFame1>
|
-> <IFrame id='2'>... parentFrame() « Change focus to the parent context. <IFame1>
</html>
</html>
<frameset cols="50%,50%">
<Fame id='11'>... defaultContent() « driver focus to top window/first frame. <html>
|
-> <Frame id='22'>... defaultContent() « driver focus to top window/first frame. <Fame11>
frame("relative=up") « focus to parent frame. <Fame11>
</frameset>
</html>
Conversion of RC to Web-Driver Java commands. link.
<frame> is an HTML element which defines a particular area in which another HTML document can be displayed. A frame should be used within a <frameset>. « Deprecated. Not for use in new websites.