Hey, I'm using Appium with WinAppDriver with Visual Studio 2015 Community Edition to Test a UWP application.
When I have a TextBlock, that has a Tapped event and I do the following:
mySession.FindElementByName("myElement").Click();
I got the name from Inspector (from Windows Kit). The test doesn't fail (so it finds the element), but it also does no click action. If it would send a click, then it would navigate to a new page, but it does not.
Could you send over your sample code and test so we can see the issue and try to repro?
I stripped down the code a bit and did a little clean up.
Create a new UWP project in VS2015.3, update Microsoft.NETCore.UniversalWindowsPlatform to current version 5.2.2, add an empty Page called Page2 and modify the MainPage.xaml like
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="contentGrid" Margin="48,80,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="42" />
<RowDefinition Height="5" />
<RowDefinition Height="42" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="ex1TB" Text="Example 1" Grid.Row="0" Grid.Column="1" Tapped="ex1TB_Tapped" />
<TextBlock x:Name="ex2TB" Text="Example 2" Grid.Row="2" Grid.Column="1" Tapped="ex2TB_Tapped" />
</Grid>
</Grid>
and the MainPage.cs:
private void ex1TB_Tapped(object sender, TappedRoutedEventArgs e)
{
Frame.Navigate(typeof(Page2));
}
private void ex2TB_Tapped(object sender, TappedRoutedEventArgs e)
{
Frame.Navigate(typeof(Page2));
}
In the Test I created a new Test - project in VS2015.3 and added Appium.WebDriver v2.0.0.1 via nuget and the UnitTest1.cs looks like the following
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Remote;
using System.Drawing.Imaging;
using OpenQA.Selenium.Appium.MultiTouch;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
protected const string AppiumUrl = "http://127.0.0.1:4723";
protected static IOSDriver<IOSElement> _driver;
protected static string AppUIDName = "2f9419d2-d335-4bd3-bc90-995d418744c5_1h1rcgxaxf0d2!App";
[TestMethod]
public void TestMethod1()
{
const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
// Launch Example
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", AppUIDName);
_driver = new IOSDriver<IOSElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
Assert.IsNotNull(_driver);
// navigate to page Example
_driver.FindElementByName("Example 1").Click(); // does not work
var el = _driver.FindElementByName("Example 1");
el.Tap(1, 1); // does not work either
// take screenshot
var img = _driver.GetScreenshot();
img.SaveAsFile("D:\\myfile.jpg", ImageFormat.Png);
}
void TapElement(IOSElement element)
{
new TouchAction(_driver).Tap(element).Perform();
}
}
}
Hi there,
I have the same behavior on some of my controls.
It happens when I've inherited from XAML Button control, or redefined the style. Any Click() or Tap() calls does any action, however _my control takes focus_.
I've checked the code of my button, and I was only overriding OnTapped() method. When overriding OnKeyUp() and OnPointer(), I was still not able to handle that click action.
Here is my test code:
new TouchAction(test.Session).Tap(signinPage.LoginButton).Perform();
signinPage.LoginButton.Click();
The signinPage variable is only a wrapper around Appium APIs.
I also face this problem with the company app. The workaround my colleague found is to double click on the problematic element instead of just the single click/tap. Well, the app is based on UWP with cordova.
@idxn can you elaborate this with an code example?
we've used the python binding so the code will look like this.
element = self._element_find(locator, True, True)
ActionChains(driver).double_click(element).perform()
From our app, if we've used the single click, the web element will just get focus so we try double click and it works.
Same issue as @cmaneu. I am sharing my test code at https://gist.github.com/tnesham/76cd39afa57554382eabdc81eaafb63b
The click event is not triggered via the Appium test code, and it would be great if this worked in VS2015/c# Test Project. But it looks like from @idxn that Python is better?
@tnesham i don't think there is any difference between them. It looks like your code doing the single click not the double click though. have you tried the double click?
@idxn In c#? I did not see the interface exposed a double click using c#, is it there?
googling for actionchains c# selenium and you should find how to implement the double click
We understand the underlying issue and are looking at addressing this soon.
Yeah! Good news! Well, do you have any date for the next release?
v0.6-beta has just been released today. Could you please verify?
@timotiusmargo This fixed the test I reported here.
Thank you for the feedback that lead to this improvement everyone 馃憤 @minimalisticMe & @cmaneu: could you please verify if this fixed the issues you encountered before we close it?
sorry for late reply. I can confirm that the fix is working like charm now.
Now there is another thing: How can I make sure the code
// take screenshot
var img = _driver.GetScreenshot();
img.SaveAsFile("D:\\myfile.png", ImageFormat.Png);
is executed after the page opens? (without a time)
Hi聽@minimalisticMe I believe this is what you're asking for.
https://github.com/Microsoft/WinAppDriver/issues/117
If you agree can you upvote it, thanks.
Most helpful comment
@timotiusmargo This fixed the test I reported here.