I am trying to automate a HTML5 video in selenium webdriver with C# - html

Video doesnt have specific ID, its from youtube. I have tried it using javascript excecutor but not working. the link is :
http://www.myhomepay.com/Tour/Nanny-Tax-Guide

Hi Parvathy please try it like below it will play the player. only catch here is why its not playing is because its inside the iframe and to perform an operation inside a specific iframe first we have to identify that iframe and then move to that iframe to perform action with webdriver
Hi i am a java guy so posting answer in java
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.myhomepay.com/Tour/Nanny-Tax-Guide");
driver.manage().window().maximize();
// first identify the play button over the youtube video player
// Please note youtube palyer is inside the iframe hence first we have
// to identify and then switch to the i fame
List<WebElement> iframe = driver.findElements(By.tagName("iframe"));
System.out.println("Total iframe on the webpage is : "+ iframe.size());
driver.switchTo().frame(iframe.get(0));
driver.findElement(By.cssSelector(".ytp-large-play-button.ytp-button")).click();
}
UPDATE : for C# you can do it like below
iFrameElement = Driver.FindElementByTagName("iFrame");
driver = Driver.SwitchTo().Frame(this.iFrameElement);
driver.FindElement(selector);
please refactor code as per C#.hope this helps

Related

Selenium cannot find element

Having some issues using Selenium web driver in Chrome.
My goal is to give the user ~15-30 seconds to log in on there own and then start doing automated testing.
The problem is after I click the login button and go to the next page, I am not able to find elements by xpath, id, etc.
public static void runTest() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.url.com");
driver.manage().window().maximize();
Thread.sleep(15000);
driver.findElement(By.xpath("//*[#id=\"content-main\"]/div/div/form/div/p/input")).click();
System.out.println("User has logged in and it has found element for Attachment Upload.");
Thread.sleep(15000);
driver.findElement(By.xpath("//*[#id=\"invoiceMenu\"]/a")).click();
}
I have also tried using explicit waits and have had no luck for example:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.id("someid")));
The error I am usually getting back is:
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //*[#id="invoiceMenu"]/a (tried for 10 second(s) with 500 milliseconds interval)
Edit:
Was able to get some of the elements (angular ones) working with a few plugins for Chrome. Element Locator and ChroPath worked fantastic. Took some playing around with, but once I got one I was able to piece together the rest of them.
I would suggest that you open the chrome console on your browser and try to interact with the element in question e.g. using:
document.getElementById('someId').click()
If you are able to click on the element like that, then you can use javascript executor in your code as follows:
((JavascriptExecutor)driver).executeScript("document.getElementById('someId').click();");

YouTube AS3 API (onReady doesn't work more ?)

YouTube AS3 API . This simple code was writed long time ago . and all was ok .
But some days ago some problems.
Early (up to 18th this month) all working OK.
Flash player using AS3 API.
public function Main()
{
super();
Security.allowInsecureDomain("*");
Security.allowDomain("*");
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.SHOW_ALL;
this._loader = new Loader();
this._loader.contentLoaderInfo.addEventListener(Event.INIT,this._onLoaderInit);
this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.errorHandlerIOErrorEvent);
this._loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.errorHandlerIOErrorEvent);
this._loader.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,this.onUncaughtError);
this.loadTime = new Date();
this._loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3");
}
private function _onLoaderInit(param1:Event) : void
{
this.player = this._loader.content;
this.player.addEventListener("onReady",this.onPlayerReady);
this.player.x = 0;
this.player.y = 0;
addChild(DisplayObject(this.player));
this._loader.contentLoaderInfo.removeEventListener(Event.INIT,this._onLoaderInit);
this._loader = null;
}
function onPlayerReady(param1:Event) : void // start from 18th this month , onReady dont fired
{
}
is somebody know this issue , or how fix it ?
Thx .
#Ivan Korneev
This is the answer. The YouTube API for AS3 (Flash) has been depreciated. I know this because it just broke in our application a few days ago, luckily we moved over the HTML5. I suggest you do the same. You can learn more here https://developers.google.com/youtube/iframe_api_reference
Thx to #All for responses.
I found some intresting thing .
apiplayer.api have function in class DirectAccessAPI
protected function forwardAPICall(param1:String, param2:Array)
{
var _loc_3:* = new APICallEvent(this.API_CALL, param1, param2);
this.loader.contentLoaderInfo.sharedEvents.dispatchEvent(_loc_3);
return _loc_3.returnValue;
}// end function
but API_CALL constant is member of APICallEvent ,
i just fix it like this
var _loc_3:* = new APICallEvent(APICallEvent.API_CALL, param1, param2);
and all ok , but now i need load apiplayer from local storage , not from youtube.
I've encountered the same issue. I use this API to display a Youtube video (chromeless player) within a flash-based game. So, sadly I'm unable to switch to the HTML5 player, as it doesn't work inside Flash. As I'm stuck with the Flash-based Youtube API, I've tried to solve this issue like OP.
After some investigations, I've found that:
- The host address of the API have been moved around February 18th. (now on the googleapis.com domain instead of youtube.com)
- After this domain move, the API is unable to load correctly from Youtube. As described in the doc, when you load the API, it should trigger a "onReady" event. Currently, that never happens.
- Calling any method described in the doc (loadVideo(), stopVideo(), etc.) on the player will now result in a "method X() doesn't exist" error. So it's not just the "onReady" event no firing, but that the API is failing to load itself
- A further proof that something is wrong with the Flash Player API on Youtube side, is that opening the chromless player URL in a browser no longer display a "Youtube" logo, as it used to be.
- My suggestion would be that they forgot to rewrote some inner URL when they moved the API from a domain to another, and now it can no longer load all its dependencies or something like that.
Unfortunately, this doesn't solve the problem, just refine where it is.
I think the only way would be to get in touch with Youtube so they "fix" whatever is wrong with their current API. Unless they disabled it voluntarily (which would be sad, as HTML5 can't cover all the uses the AS3 player did).
Try https for Youtube path. Eg: .load(new URLRequest("https://www.youtube.com/api...etc
Instead of http://www.youtube.com/apiplayer?version=3
try: https://youtube.googleapis.com/apiplayer?version=3
try this open source solution https://github.com/myflashlab/AS3-youtube-parser-video-link

Back Navigation using Xamarin Razor on WebViewClient

Please help me to find the way how to navigate back on webviewclient using back button on android.
I am using Xamarin hybrid app using Razor views,
I am using loadDataWithBaseURL method to find each method and move on that page, like following:
if (method == "SignIn")///sign-in.html
{
var template = new SignIn();
var page = template.GenerateString();
webView.LoadDataWithBaseURL("file:///android_asset/", page, "text/html", "UTF-8", null);
}
The above code I am using in ShouldOverrideUrlLoading(WebView webView, string Url)
the URL is passed as "hybrid:SignIn?"
Now back navigation is not working either on using OnBackPressed() method, or using OnKeyDown()
I also tried, WebBackForwardList, I can see in debug mode te current items in it , but no any url to go back on.
The url is always "about:blank"
and page is showing blank on GoBack() method.

WP8 Play sound when application is onbackground

Developing tools : Visual Studio 2012, target wp platform : wp8.
I am facing the above problem:
When my application is running on background and i am receiving a notification i vibrate the phone successful and i want to play a specific sound.
What i have tried so far:
Player = new MediaElement();
Player.AutoPlay = true;
Player.Volume = 5;
Player.Source = new Uri("/data/alert.mp3", UriKind.RelativeOrAbsolute);
Player.MediaOpened += (Object s, RoutedEventArgs args) =>
{
Player.Play();
};
I i am not getting any exception but no sound. Neither on foreground nor background .
Am i missing something?
I will appreciate any help.
You can't use the MediaElement API to play notification sounds when the app is in background. In order to launch a notification and play a custom sound, you need to use the ShellToast and use the Sound property via reflection.
Here is how play a custom notification sound from background (MSDN link) Using custom sounds in toasts on Windows Phone 8 Update 3
EDIT: When the app is running in foreground, you can use the same technique (ShellToast with Sound).
Even MediaPlayer class can help you play songs and media in the background when you are showing a toast or a small pop up dialog.
Check here : http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.play.aspx

Playing Soundbite in WP8 App

I'm trying to write a WP8 app that plays a short sound when a button is pressed, but I cannot seem to figure out how to play the sound. Here's a quick example of my code:
XAML
<Rectangle x:Name="Rect1" Grid.Row="0" Grid.Column="0" Tap="RectTapped" Fill="White" />
App.cs
private void RectTapped(object sender, System.Windows.Input.GestureEventArgs e)
{
MediaElement sound = new MediaElement();
sound.AutoPlay = false;
sound.Source = new Uri("Assets\\Sounds\\bark-1.wav", UriKind.Relative);
sound.Play();
}
When testing on my Nokie 820 device no sound plays. I can't understand why.
Is there something I'm doing wrong? The .wav is in my resources.
I've read that MediaElement shouldn't be used for this task. I've tried using the SoundEffect class in Xna.Framework.Audio; following the example from MSDN but that also fails because I couldn't use Content.Load as Load was not an available method of the Content class.
I've also looked at XAudio2, but as I do not know C++ I can't get my head around the examples.
You need to add MediaElement to your XAML tree
this.LayoutRoot.Children.Add(sound);
Instead of a Rectangle, use a Button. Also, MediaElement is good for playing short sounds in Silverlight applications. Make sure that the control is a part of your visual tree (add it in XAML). Then bind to the button Click event handler:
private void YourClickHandler(object sender, RoutedEventArgs e)
{
myMediaElement.Source = new Uri("/Assets/Sounds/bark-1.wav", UriKind.Relative);
myMediaElement.Play();
}
You should be using the XNA SoundEffect class instead of the MediaElement because, well, you're playing sound effects.
The documentation is bad for this area, but this is how you do it:
effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
so to play a soundeffect from your app package:
var stream = Application.GetResourceStream(filepath);
effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
The advantage over MediaElement is that the SoundEffect does not need to be in the visual tree (and also it doesn't screw up the background audio player). The disadvantage is that you have none of the (sometimes useful) events that you have on MediaElement.
For Windows Phone 8.1 Silverlight, take the first two answers (from #DenDelimarsky and #onmyway133) to play the sound.
Without adding MediaElement to XAML sound not played in my case.
Use below code to play sound:
private void YourClickHandler(object sender, RoutedEventArgs e)
{
MediaElement myMediaElement = new MediaElement();
myMediaElement.Source = new Uri("/MP3/AirHornTwoBlows.mp3", UriKind.Relative);
LayoutRoot.Children.Add(myMediaElement);
myMediaElement.Play();
}
Remove the line
sound.AutoPlay=false;
or change it to:
sound.AutoPlay = true;
it will work then.