CefSharp webpage element click

后端 未结 2 1203
生来不讨喜
生来不讨喜 2020-12-10 18:26

I\'m trying to do simple click on some page element(like a btn or link).

I have wrote 2 functions for clicking via xpath and via CSS selectors.

Both of those

2条回答
  •  萌比男神i
    2020-12-10 18:47

    The problem was in security limitations of JS code.

    Solution of the problem is:

    1. Get coordinates of a button/link with JS code
    2. Simulate click action on it with CEF:

      public void MouseClick(int x, int y)
      {
          Browser.GetBrowser().GetHost().SendMouseClickEvent(x, y, MouseButtonType.Left, false, 1, CefEventFlags.None);
          Thread.Sleep(15);
          Browser.GetBrowser().GetHost().SendMouseClickEvent(x, y, MouseButtonType.Left, true, 1, CefEventFlags.None);
      }
      

提交回复
热议问题