簡體   English   中英

有些點擊不能使用selenium獨立服務器在Safari瀏覽器中工作

[英]Some click dont work in Safari browser using selenium standalone server

嗨我正在使用Selenium Standalone Server和Selenese命令執行程序在Mac OS X上測試Safari。我在單擊特定頁面上的某些按鈕時遇到問題。 同樣的點擊在其他瀏覽器中也能完美運行,如firefox(Windows),chrome(Windows + Mac),IOS模擬器,IE。 我也能通過id獲取按鈕。通過使用getText()獲取按鈕文本來確認。 在click命令之后,沒有任何事情發生。 我嘗試過使用button.click(),button.submit()。 還使用id,xpath,類來查找按鈕。 正如我所提到的:我能夠獲得id,只是點擊不起作用。 有什么建議么? 一些代碼是:

public static WebDriver getSafariDriver()
    {
        try
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setBrowserName("safari");
            capabilities.setJavascriptEnabled(true);
            CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"), new URL("http://www.google.com/"), capabilities);
            WebDriver driver = new RemoteWebDriver(executor, capabilities);
            return driver;
        } catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        return null;
    }

是否有通過命令提示符的解決方法? 或者其他任何我可以嘗試或錯過的東西? 請幫忙。

嘗試使用javascript執行器

WebElement yourelement= driver.findElement(By.id("btn"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", yourelement);

我有同樣的問題。 經過長時間的調試后,我發現問題是在Safari綁定之前JS沒有完全加載,所以在進行測試之前我必須在頁面加載后等待很長時間。

我服務器端渲染了按鈕(反應組件),但是當文檔准備好時實現了按鈕的功能。

Safari 10+,OSX El Capitan和Selenium 3.0.1也遇到了同樣的問題

另一種方法可能是發送一個用Python實現的RETURN鍵:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Safari()
driver.get('http://localhost:8000')
element = driver.find_element_by_id("submit")
element.send_keys(Keys.RETURN)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM