Selenium iframe selection issue - iframe

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.

Related

How to close Microsoft Edge browser's new tab in c# code

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();

Launching a webpage in browser from an Adobe Air app not working

I've got a webpage I want to hook in to my Adobe Air app. It's running JavaScript, so I can't open it in the app, but I'm trying to launch it in the default system browser.
Here's the code that's supposed to be launching the page:
public function beginModule():void {
var loader:HTMLLoader = new HTMLLoader();
var gameURL:URLRequest = new URLRequest("file:///path/to/file.html");
loader.navigateInSystemBrowser = true;
loader.load(gameURL);
}
I've also tried using
flash.net.navigateToURL(gameURL);
but that had no effect.
Every time I hit the above method, that block executes but nothing happens other than a quick cursor change-- no browser opened, no change in the app. What am I missing here?
Before you start, check if the HTML page is properly running in the browser.
To open a HTML page in flex, use the HTML tag: <mx:HTML></mx:HTML>
Something like this: https://snipt.net/anishnair/flex-show-html-page/?key=28838d54ac287180032dee000ce33a74
Thank you.
Regards,
Anish
Simply use :
navigateToURL(url,"_blank");
to navigate to the url in the web-browser.

how to locate elements on a different webpage?

I'm new to java and webdriver. My web-applications adds some data to a table on a webpage. If the addition is successful, a new web page is opened and the success message is displayed on the new page. If the addition is not successful, a javascript alert is thrown. After accepting the alertHow do I check the presence of an the message on the new webpage using webdriver?
If it is opening in new window you need to switch the control to new window first
Find the logic here to switch the control between windows
After switching the control to new window you can verify whatever you want. Either element or text.
isElementPresent? method logic here .
isTextPresent? method logic here.
If I understand the question correctly, after sending the data to the table, if the sending is successful then the window is loaded with a new webpage else an alert appears once you accept the alert the window is loaded.
After sending the data, check for the presence of the alert, if the alert is present then accept it. Next is verifying whether a text is present in the newly loaded webpage or not.
public void isAlertPresent(){
try {
driver.switchTo.alert().accept();
}
catch ( NoAlertPresentException e ){
}
System.out.println(driver.findElement(By.tagName("body")).getText().contains("Expected Message"));
If the location where the message appears is static then I would suggest you to use a better approach than the above like if an element has that text
WebElement element = driver.findElement(By.id("elementID"));
System.out.println(element.getText().trim().equals("Expected Message"));

How to embed "Share on Facebook" button into Flex application?

I'm trying to duplicate the behaviour of the "Share on Facebook" button from Youtube. Basically, inside a Flex app I'll have a button and when I click it I want a popup that enables me to post something on the wall.
While it is possible to make a call to javascript to open the pop-up I want to be able to set the images and the text of my posting.
Do you know how I could set the images or text as a paramter to the sharer window?
Thank you!
This is fairly straightforward to do. Youtube uses the Facebook API which pops up a new window (Info on Facebook sharer API).
To do this in flex,
Create a button that onClick will call a javascript method, ExternalInterface.call("fbLink", "www.yahoo.com");
In your HTML file (most likely index.template.html) add the JavaScript method, fbLink which does the following:
function fbLink(url) {
window.popup("http://www.facebook.com/sharer.php?u=" + url, {height:440, width:620, scrollbars:true})
}
Now when a user clicks on the button they will be sharing the link "yahoo.com" with facebook account.
as I understood you asking for some help in accessing js popup in html page of facebook share button, so you should use ExternalInterface in this casa and access needed DOM node using getElementById function in your js interface.
In other case I want propose you to read another one way http://www.riaxe.com/blog/flex/publish-into-facebook-wall-from-flex/
It seems that you want to have a button on the flash application and once clicked it opens the facebook page that shares the video/image that pertains to the clicked button. What you want to do is simply create a button that on click opens a new website to facebook using their share api which has the following format:
var facebookShare:String = "http://www.facebook.com/share.php?u=' + encodedVideoLink + '&t='+ encodedVideoText";
Where the u parameter stands for the link that you wish to share, and the t parameter stands for the title of the piece that you want to share, whether it be a picture or video.
You want to add an event listener on MouseEvent.CLICK that has as its callback function a method that handles the opening of the facebook page passing the facebookShare variable as shown above. To open another page on your browser you can use this AS3 Class called URLNavigator: http://www.danishmetal.dk/project/source/com/zorked/URLNavigator.as
To sum it up, something along these lines would do:
var facebookShare:String = "http://www.facebook.com/share.php?u=' + encodedVideoLink + '&t='+ encodedVideoText";
facebookButton.addEventListener(MouseEvent.CLICK, this._goToUrl(facebookShare));
private function _goToUrl(link:String):Function {
var window:String = "_blank",
feats = "",
thisOverlay:Object = this; // to not lose scope when returning a func
return function (e:MouseEvent):void {
trace("Opening link to:"+link);
try { URLNavigator.ChangePage(link, window, feats); }
catch (e:Error) { trace("error launching "+link+" in "+window+" with feature set "+feats); }
}
}
I hope that helps. If you have questions regarding the code please let me know.

ASPnet web Form Navigation

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.

Resources