ChromeDriver で特定要素のタップイベント
touchstart
touchend
をトリガーするにはどのようにコーディングすればよいでしょうか。
使ったことが無いので、検索結果からの推測ですが。
以下のようなものを使うことになるでしょう。これらを調べて試してみてください。
タッチスクリーンインタフェースの取得
selenium/dotnet/src/webdriver/IHasTouchScreen.cs
selenium/dotnet/src/webdriver/Interactions/TouchAction.cs
おそらく存在すればオブジェクトが返り、無ければnullが返るか例外が発生するでしょう。
touchstart
, touchend
について。
selenium/dotnet/src/webdriver/ITouchScreen.cs
selenium/dotnet/src/webdriver/Interactions/TouchActions.cs
以下のDown(locationX, locationY);
がtouchstart
、Up(locationX, locationY);
がtouchend
に相当すると考えられます。
/// <summary>
/// Allows the execution of the gesture 'down' on the screen. It is typically the first of a
/// sequence of touch gestures.
/// </summary>
/// <param name="locationX">The x coordinate relative to the view port.</param>
/// <param name="locationY">The y coordinate relative to the view port.</param>
void Down(int locationX, int locationY);
/// <summary>
/// Allows the execution of the gesture 'up' on the screen. It is typically the last of a
/// sequence of touch gestures.
/// </summary>
/// <param name="locationX">The x coordinate relative to the view port.</param>
/// <param name="locationY">The y coordinate relative to the view port.</param>
void Up(int locationX, int locationY);
特定要素の x,y 位置を取得するには、以下のような手順で出来るのでは?
そして、この記事のように、それが実際の表示範囲外だった場合は、スクロール等して画面上に持ってくる必要があるでしょう。
Selenium ChromeDriver how to click elements with negative x,y pixel locations? C#
// Must close unless the popup may (or may not) cover the next link.
var closeButton = Session.Driver.FindElement(By.Id(id))
.FindElements(By.CssSelector("a.cmg_close_button"))
.FirstOrDefault();
if (closeButton != null)
{
Wait.Until(d => closeButton.Displayed);
if (closeButton.Location.Y < 0 || closeButton.Location.X < 0)
{
Log.Error("Could not close button. The popup displayed the close_button off-screen giving it a negative x or y pixel location.");
}
else
{
closeButton.Click();
}
}