【问题标题】:Unable to get 'scrollintoview' to work in javascript无法让“scrollintoview”在 javascript 中工作
【发布时间】:2018-02-02 11:13:20
【问题描述】:

我有以下功能。如果按钮在视图中,它工作正常。如果它在可见页面下方,则表明它试图与可见视图之外的对象交互失败。我曾尝试使用“scrollintoviewifneeded”,但我收到一条消息说对象不支持此功能? 我真的被困住了,可以接受任何建议或帮助(自动化新手)。

function ClickByButtonText(/*buttonVisibleText*/)
{
  var buttonVisibleText = "VALIDATE"
  /* convert String to object */ 
  var buttonText = ConvertToObject(buttonVisibleText);

  //Waits upto 10 seconds for page to load
  Sys.Browser("*").Page("*").Wait("10000");

   waitUntilObjectIsVisible("//button[contains(text(),'" + buttonText + "')]");

   var page = Sys.Browser("*").Page("*")
   page.FindChild("contentText", buttonText, 500).Click();
}

【问题讨论】:

    标签: javascript automation


    【解决方案1】:

    所以我很清楚你想要什么。

    你有一个按钮可以让你的页面滚动直到有东西出现?

    我从未使用过“自动化”,我假设它是用于自动 e2e 测试的框架。

    但是

    为什么不使用简单的 jquery 呢? How do I get an element to scroll into view, using jQuery?

    如果您无法为此使用 jquery,则必须自己制作一个(与框架兼容的)函数,类似于

    while(bla){
    
       // get co-ords
       // get offset
       // if co-ords - offset is not the result you want, scroll ++
       // if co-ords - offset is the result, get out of loop
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-26
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多