[英]How to stop Selenium clicking an element off-screen on iOS Safari?
我在自動化網頁時遇到問題,我正在使用:
問題是我需要點擊一張圖片,這張圖片是頁面底部的 75%。 問題是因為它的一些在頁面上可見,Selenium 可以看到它,因此會嘗試點擊它。 當它點擊它時,它實際上點擊了 Safari 菜單; 我認為這是因為它試圖單擊圖像的中心,如果 Safari 菜單不存在,那么這就是圖像的中心所在的位置。 我附上了 2 個屏幕截圖來說明這一點。 我有三個問題
提前致謝。
HTML
<a id="3245248" class="detail-info" href="#">
<img title="Order Information" src="/Content/images/24x24/info.png"></a>
C# 您可以通過傳遞 id 名稱單擊圖像:
driver.FindElement(By.CssSelector("#3245248 img")).Click();
I found the solution to get Selenium to correctly scroll the element into view, somebody else had answered a similar question and their code worked brilliantly for me using C#, iOS and Safari, the code is below.
IWebElement element = driver.FindElement(By.xpath("Value"));
IJavascriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("arguments[0].scrollIntoView();", element);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.