Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some click dont work in Safari browser using selenium standalone server

Hi I am using Selenium Standalone Server along with Selenese command executor for testing on Safari on Mac OS X. Im facing issues in clicking some buttons on specific pages. The same clicks work perfectly in other browsers like firefox(Windows),chrome(Windows+Mac),IOS simulators,IE. Also im able to get the button through id.Confirmed by getting the buttons text using : getText(). Only thing is nothing happens after the click command. I have tried using button.click() , button.submit(). also used id, xpath , class to find the button. As i mentioned : Im able to get the id, just that the click is not working. any suggestions? some of the code is:

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;
    }

Is there any workaround through command prompt ? Or anything else that i can try or am missing out? Please help.

like image 255
user1643707 Avatar asked Sep 03 '12 12:09

user1643707


2 Answers

I had the same issue with Safari 10+, OSX El Capitan and Selenium 3.0.1

Another alternative may be to send a RETURN key implemented in Python:

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)
like image 172
vaggos2002 Avatar answered Nov 11 '22 06:11

vaggos2002


Try using javascript executor

WebElement yourelement= driver.findElement(By.id("btn"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", yourelement);
like image 36
ra_sangeeth Avatar answered Nov 11 '22 08:11

ra_sangeeth