【问题标题】:Selenium C# Get href under the mouse coordinatesSelenium C#获取鼠标坐标下的href
【发布时间】:2020-12-18 12:11:49
【问题描述】:

有一个网站,个人资料与他们的个人资料照片一起列出。

我正在尝试获取该个人资料照片的 href(我不是在尝试获取照片的 href,我正在尝试对 href 进行个人资料)。所以我需要在鼠标光标下获取元素。在基本的 c# 浏览器中有简单的代码:Link 但我正在使用 Selenium 驱动程序,所以我认为我需要通过执行 JavaScript 来做到这一点。 所以我找到了在 selenium 上使用 elementfrompoint 和 javascript 的线程,但它返回我“null” enter link description here

这是该个人资料照片的类别。 我正在尝试获取 href "/en/community/ProfileUrlHere"

编辑:我尝试过使用

ele = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript(
                    "return document.elementFromPoint(arguments[0], arguments[1])", 
                    Cursor.Position.X, Cursor.Position.Y);

但它返回 null 似乎我的坐标有问题,“Cursor.Position.X,Cursor.Position.Y”我需要使用“event.ClientX”获取坐标

              String s_Script = "var X, Y; "
              
               + "  X = event.clientX; "
               + "  Y = event.clientY; "
               + " alert(X);"
                + "return new Array(X, Y);";

但我得到“OpenQA.Selenium.WebDriverException: 'javascript error: Cannot read property 'clientX' of undefined”这个错误。

【问题讨论】:

    标签: c# selenium selenium-chromedriver


    【解决方案1】:

    我试过了

    ele = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript(
                    "return document.elementFromPoint(arguments[0], arguments[1])", 
                    Cursor.Position.X, Cursor.Position.Y);
    

    但它返回 null 似乎我的坐标有问题,“Cursor.Position.X,Cursor.Position.Y”我需要使用“event.ClientX”获取坐标

    但我得到“OpenQA.Selenium.WebDriverException: 'javascript error: Cannot read property 'clientX' of undefined”这个错误。

    【讨论】:

      猜你喜欢
      • 2011-01-05
      • 2010-12-03
      • 1970-01-01
      • 2021-01-05
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-14
      相关资源
      最近更新 更多