Safari Browser: Switch to frame is not working - selenium

I am trying to run few test on Mobile Emulators (Safari Browser) and stuck at a problem. Where after switching to an Iframe I am not able to do any action.
There is already a closed issue for that, however I didn't find any solution after going though this thread.
https://github.com/appium/appium/issues/5832
Code which is causing issue
public PaymentPage fillCreditCardInformation(String cardNumber, String expiryDate, String cvv, String postal ){
switchToPaymentFrame();
WebElement cardNumberEditbox = driver.findElement(By.name("cardnumber"));
}
private void switchToPaymentFrame() {
WebElement frame = driver.findElement(By.name("__privateStripeFrame3"));
driver.switchTo().frame(frame);
}
Emulator Used: Iphone 6s, IPad Mini
Webdriver Version: 3.4.0
Safari Driver: 2.48
Stacktrace:
org.openqa.selenium.WebDriverException: undefined is not an object
(evaluating 'a.querySelectorAll') (WARNING: The server did not provide
any stacktrace information) Command duration or timeout: 30.48 seconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'DL0019', ip: '127.0.1.1', os.name: 'Linux',
os.arch: 'amd64', os.version: '4.4.0-96-generic', java.version:
'1.8.0_131' Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{noReset=true, safari=true,
browserstack.tunnelIdentifier=, browserstack.asyncStop=true,
language=Apache-HttpClient/4.5.3 (Java/1.8.0_131),
browserstack.selenium_version=3.4.0, deviceName==iPad Retina (9.1)
[556DF534-C4AE-48B6-8ED3-BAF86198074A], platform=MAC,
browserstack.video.disableWaterMark=true, desired={noReset=true,
browserstack.tunnelIdentifier=, browserstack.asyncStop=true,
language=Apache-HttpClient/4.5.3 (Java/1.8.0_131),
browserstack.selenium_version=3.4.0, deviceName==iPad Retina (9.1)
[556DF534-C4AE-48B6-8ED3-BAF86198074A], platform=MAC,
browserstack.video.disableWaterMark=true, acceptSslCerts=false,
newCommandTimeout=300.0, browser=ipad, platformVersion=9.1,
acceptSslCert=false, browserName=safari, platformName=iOS,
64bit=false, browserstack.debug=true, orientation=portrait,
browserstack.ie.noFlash=false, os_version=,
mobile={"browser":"tablet","version":"iPad Mini 4-9.1"},
browserstack.geckodriver=0.16.0, version=, browserstack.video=true,
safariIgnoreFraudWarning=true, orig_os=macelc, realMobile=false,
deviceOrientation=PORTRAIT, device=iPad Retina, proxy_type=node},
acceptSslCerts=false, newCommandTimeout=300.0, browser=ipad,
platformVersion=9.1, webStorageEnabled=false, acceptSslCert=false,
browserName=safari, takesScreenshot=true, javascriptEnabled=true,
platformName=iOS, 64bit=false, browserstack.debug=true,
networkConnectionEnabled=false, orientation=portrait,
browserstack.ie.noFlash=false, warnings={}, os_version=,
mobile={"browser":"tablet","version":"iPad Mini 4-9.1"},
browserstack.geckodriver=0.16.0, databaseEnabled=false, version=,
browserstack.video=true, safariIgnoreFraudWarning=true,
orig_os=macelc, realMobile=false, locationContextEnabled=false,
deviceOrientation=PORTRAIT, device=iPad Retina, proxy_type=node}]
Session ID: 6bf643515813d0ccbe5fe75300ac2d8ea15a5960
*** Element info: {Using=name, value=cardnumber}

Can you try this:
Change:
private void switchToPaymentFrame() {
WebElement frame = driver.findElement(By.name("__privateStripeFrame3"));
driver.switchTo().frame(frame);
}
To:
private void switchToPaymentFrame() {
WebDriverWait wait1 = new WebDriverWait(driver, 10);
wait1.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("__privateStripeFrame3")));
}

Seems to me like a known issue.
Simply doesn't work.
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/7658

Related

Regarding issue org.openqa.selenium.UnhandledAlertException: Modal dialog present: A script on this page may be busy

I am currently using Java webdriver 2.53.1 for firefox version 2.46.0. I am getting this below error when run my script for a long time. Since I have different profiles to run multiple scripts at a time using same browser. this firefox browser seems getting crashed.
Please find below error details
org.openqa.selenium.UnhandledAlertException: Modal dialog present: A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.
Script: https://website/js/jq…596b2b8fa35fe3a634ea342d7c3.js:1
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'MACHINE NAME', ip: 'Ip address', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=47.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 39cfd1aa-1d74-4b18-bdcd-5255a2b90127
at sun.reflect.GeneratedConstructorAccessor51.newInstance(Unknown Source)
Also I have applied two solutions
say
1.
DesiredCapabilities capabilites = new DesiredCapabilities();
capabilites.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT);
driver = new FirefoxDriver(capabilites);
as per the below link
https://www.google.com.au/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&cad=rja&uact=8&ved=0ahUKEwjf4_vy-9rUAhXEEbwKHY8_CTUQFghBMAU&url=https%3A%2F%2Fsupport.mozilla.org%2Fen-US%2Fkb%2Fwarning-unresponsive-script&usg=AFQjCNGh0FhTTjSvFduBRRe36UJCGXz8qA
But still the issues seems not fixed on mt script.
Could anyone provide a solution for this?
This error from my experience is only thrown when you are trying to do a page navigation but have not handled an on screen alert. You need to user the IAlert class to accept or dismiss this alert to continue.
First find what command is triggering the alert, then handle the alert.
If you elaborate more on your issue I may be able to help more, it would be helpful if you included the selenium code that is causing this exception.
Here are some functions I use to deal with alerts.
public void AcceptAlert()
{
try
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.AlertIsPresent());
IAlert alert = Driver.SwitchTo().Alert();
alert.Accept();
}
catch (Exception)
{ }
}
public void DismissAlert()
{
try
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.AlertIsPresent());
IAlert alert = Driver.SwitchTo().Alert();
alert.Dismiss();
}
catch (Exception ex)
{
log.Debug(ex.Message);
}
}

Android Emulator default browser can't take screenshot

My Emulator android phone has android default browser, when appium test the android default browser, it can't take screenshot on failure using TakesScreenshot.How can I to solve it.
I am using Selenium Remote Webdriver as driver instance
public synchronized static void captureScreenshot(WebDriver driver, String screenshotName) {
try {
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("./Screenshots/"
+ screenshotName + ".png"));
System.out.println("Screenshot taken");
filePath=timestamp()+ screenshotName + ".png";
} catch (Exception e) {
System.out.println("Exception while taking screenshot "
+ e.getMessage());
}
}
CONSOLE LOGS :
Exception while taking screenshot An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 660.36 seconds
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'DocASAP-mac-mini.local', ip: '192.168.1.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.5', java.version: '1.7.0_79'
Session ID: f8bcc2d5-a00d-43c5-8a8a-157d2fbe6260
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{platform=ANDROID, javascriptEnabled=true, acceptSslCerts=true, browserName=Browser, networkConnectionEnabled=true, desired={newCommandTimeout=60, platform=ANDROID, autoAcceptAlerts=true, acceptSslCerts=true, deviceName=192.168.56.101:5555, platformName=Android, browserName=Browser, setAcceptUntrustedCertificates=true, version=5.1.0}, locationContextEnabled=false, deviceUDID=192.168.57.101:5555, version=5.1.0, newCommandTimeout=60, platformVersion=5.1, autoAcceptAlerts=true, databaseEnabled=false, deviceName=192.168.57.101:5555, platformName=Android, webStorageEnabled=false, setAcceptUntrustedCertificates=true, warnings={}, takesScreenshot=true}]

Difficult to run the script in selenium webdriver which contains HtmlUnitDriver

I am unable to run the basic selenium script which contains the HtmlUnitDriver. If I try to run the code I get the following error.
Code:
public class SampleUnitDriver
{
public static void main(String[] args) throws Exception
{
HtmlUnitDriver unitDriver = new HtmlUnitDriver();
unitDriver.get("http://google.com");
System.out.println("Title of the page is -> " + unitDriver.getTitle());
Thread.sleep(3000L);
WebElement searchBox = unitDriver.findElement(By.className("gsfi"));
searchBox.sendKeys("Selenium");
WebElement button = unitDriver.findElement(By.name("gbqfba"));
button.click();
System.out.println("Title of the page is -> " + unitDriver.getTitle());
}
}
Error:
Title of the page is -> Google
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Returned node was not a DOM element
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'user-PC', ip: '192.168.1.52', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51'
Driver info: driver.version: SampleUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByCssSelector(HtmlUnitDriver.java:1060)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByClassName(HtmlUnitDriver.java:1032)
at org.openqa.selenium.By$ByClassName.findElement(By.java:391)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1725)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1721)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1367)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1721)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:606)
at com.digitalmqc.automation.action.SampleUnitDriver.main(SampleUnitDriver.java:16)
The class name gsfi of the input box is generated by javascript so you have 2 options:
Easy One: Just select it by using the id lst-ib
Better One: Wait for the element to be fully interactive. The reason behind this one being better is that you are trying to input text into the box which javascript plays a role. The former option may throw some unexpected errors.

Selenium code not working on Safari browser

I have written the following code to select Account - Register menu option in http://www.snapdeal.com
public void selectRegisterAccount(String object){
System.out.println(object);
writeLog("Executing keyword selectRegisterAccount");
try{
Thread.sleep(1000);
actions = new Actions(browser);
actions.moveToElement(browser.findElement(By.xpath(project.getProperty("XPath_linkAccount")))).perform();
actions.moveToElement(browser.findElement(By.xpath(project.getProperty("XPath_linkRegister")))).click().build().perform();
browser.switchTo().frame("loginIframe");
currentElement = browser.findElement(By.xpath(project.getProperty(object)));
browser.switchTo().defaultContent();
}catch(Exception e){
Assert.assertNotNull(currentElement,"Failed to open Register page.");
writeLog("Failed to open Register page because of "+e.getMessage());
}
writeLog("Ending keyword selectRegisterAccount");
}
My project properties is as follows
testSiteURL = http://www.snapdeal.com
#####################################################################################################################################
************************************************BUTTONS************************************************************
#####################################################################################################################################
XPath_btnPinCodeClose = //*[#id='pincodeSalienceComponent']/div[2]/i
XPath_btnMobileNumberEmail = //*[#id='login-register-modal']/div[2]/div[2]/div[1]/div
#####################################################################################################################################
************************************************HEADINGS************************************************************
#####################################################################################################################################
XPath_headingRegister = //*[#id='login-register-modal']/div[2]/div[2]/p[1]
#####################################################################################################################################
************************************************INPUTS************************************************************
#####################################################################################################################################
XPath_txtRegisterMobile = //*[#id='j_number']
XPath_txtRegisterEmail = //*[#id='j_username_new']
XPath_txtRegisterPassword = //*[#id='j_password']
XPath_txtRegisterConfPassword = //*[#id='j_confpassword']
XPath_txtRegisterPinCode = //*[#id='j_pincode']
#####################################################################################################################################
************************************************LINKS************************************************************
#####################################################################################################################################
XPath_linkAccount = //*[#id='accountHeader']/div[1]
XPath_linkRegister = //*[#id='accountHeader']/div[2]/div[2]/div[1]/p/span[2]
#####################################################################################################################################
************************************************TITLES************************************************************
#####################################################################################################################################
Title_homePage = Shop Online in India at Snapdeal - India's Largest Shopping Site
The above code works fine with Chrome and Mozilla, but when executed for Safari I see the below exception
2016-03-20 19:22:57,373 DEBUG [RegisterTest - 2] Executing keyword selectRegisterAccount
2016-03-20 19:22:58,423 DEBUG [RegisterTest - 2] Failed to open Register page because of Unknown command: {"id":"n4vqmxrlur2e","name":"mouseMoveTo","parameters":{"element":":wdc:1458481961848"}} (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'Srini-PC', ip: '10.0.0.2', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_20'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{browserName=safari, takesScreenshot=true, javascriptEnabled=true, version=5.1.7, cssSelectorsEnabled=true, platform=WINDOWS, secureSsl=true}]
Session ID: null
2016-03-20 19:22:58,424 DEBUG [RegisterTest - 2] Ending keyword selectRegisterAccount

cucumber jvm selenium example

I am using standart exsample:
cucumber-jvm-selenium-example
When I run test:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.michalvich.cucumber.selenium.example.GoogleSearchTest
Feature: Search on Google
As an user
I want to search on Google
So that I can see results
Scenario: results are shown # com\michalvich\cucumber\selenium\example\GoogleSearch.feature:6
Given the page is open "http://www.google.com" # GoogleSearchScenario.the_page_is_open(String)
[1A Given the page is open "http://www.google.com" # GoogleSearchScenario.the_page_is_open(String)
When I search for "Cucumber" # GoogleSearchScenario.I_search_for(String)
[1A When I search for "Cucumber" # GoogleSearchScenario.I_search_for(String)
org.openqa.selenium.NoSuchElementException: Unable to locate element with name: q
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 15:53:30'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:749)
at org.openqa.selenium.By$ByName.findElement(By.java:292)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1247)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1244)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:987)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1244)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:393)
at com.michalvich.cucumber.selenium.example.GoogleSearchScenario.I_search_for(GoogleSearchScenario.java:26)
at ?.When I search for "Cucumber"(com\michalvich\cucumber\selenium\example\GoogleSearch.feature:8)
But if I change driver:
System.setProperty("webdriver.chrome.driver", "path\\to\\chromedriver.exe");
driver = new ChromeDriver();
It works.
You need to wait for Google ajax to refresh, otherwise you will only have Google return as the page title
#When("^I search for \"([^\"]*)\"$")
public void I_search_for(String search) throws Throwable {
WebElement element = driver.findElement(By.name("q"));
element.sendKeys(search);
element.submit();
// Google ajax wait for 5 seconds
long end = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < end) {
WebElement resultsDiv = driver.findElement(By.className("gssb_e"));
// If results have been returned, the results are displayed in a drop down.
if (resultsDiv.isDisplayed()) {
break;
}
}
}