WebDriver - element is not clickable Chrome

前端 未结 8 1146
攒了一身酷
攒了一身酷 2021-02-04 10:56

I have following problem. I run test on Firefox and Chrome. On Firefox test run correctly but on Chrome SauceLabs give a message:

unknown error: Element is not          


        
8条回答
  •  既然无缘
    2021-02-04 11:17

    I. If the button is on the bottom of the page, the following code could be used to get you to the bottom via JavaScript from where the click can be executed:

    (driver as IJavaScriptExecutor).ExecuteJavaScript("window.scrollTo(0,document.body.scrollHeight - 150)");

    The same action could be done via C# with the Actions class provided by Selenium. This will get you to the bottom of the page----->

    new Actions(Driver).SendKeys(Keys.End).Perform();

    Keys.End could be switched with Keys.PageDown // Keys.Space

    II. If you want to get to the exact position of the element you can:

    1.Get the element's Y location---> var elementToClick = driver.findElement(By.{Anything}(""));

    2.Execute the following JS---> (driver as IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,{0})", elementToClickYLocation.Location.Y));

    3.Click the element---> elementToClick.click();

提交回复
热议问题