WebDriverException when clicking the OK button on a Anyline dialog - java

So all I want to do is clicking on dialog that only pops up on the iOS Simulator (iOS 14.5, Appium Java-Client 7.3.0).
The dialog comes from Anyline because of course I have no camera on the simulator.
If there is any way to hide this dialog it would solve my problem too, I tried this with capabilities but it doesn't worked.
cap.setCapability("autoAcceptAlerts", false);
cap.setCapability("autoDismissAlerts", false);
Selecting the dialog is no problem, i can check that the Dialog is here:
#iOSXCUITFindBy(accessibility = "Anyline SDK cutout UI")
public IOSElement anylineDialog;
This is how it looks like:
So the next step would be to just click the ok button it worked at the beginning but now I can't even select it in the Appium Inspector anymore. Before I just used this:
#iOSXCUITFindBy(accessibility = "OK")
public IOSElement okButton;
I don't know why it doens't work anymore, but I can still select it with the help of TestProject.
I tested a lot of different selectors but it doesn't worked. (the one with accessibility = "OK" is also recommended in this tool)
I always get this exception and I don't know how to fix it, try catch also doesn't work:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
I tried out the stuff on this page and I also get the OK button as the only button as this code snippet shows.
HashMap<String, String> args = new HashMap<>();
args.put("action", "getButtons");
List<String> buttons = (List<String>)driver.executeScript("mobile: alert", args);
Also from the same site, I tried this with the same result.
args.put("action", "accept");
args.put("buttonLabel", "OK");
driver.executeScript("mobile: alert", args);
Maybe this is to specific but if someone has an idea how I could solve it, I would be very thankful.

The iOS bug you mentioned has been fixed in Appium 1.22.1 and 2.0.0-beta. Be sure you are running one of those versions and you should be fine.

Related

How to "handle" an alert as per UnhandledAlertException?

This topic is sadly very poisoned by non-applying answers, e.g. 1, 2, 3, 4, etc. pp.
The issue:
One may do an action which, when successful, makes the website raise an alert.
E.g. click on a "logout" button to see an "Are you sure you want to logout?" alert:
public class Logout extends PageObject {
static final Target LOGOUT = /* logout button, which will display the alert when clicked */;
public Performable logout() {
return Task.where("{0} clicks on Logout"
, Ensure.that(LOGOUT).isDisplayed()
, Click.on(LOGOUT) // done manually: alert visible; done by Serenity: no alert
);
}
}
Serenity will cause an org.openqa.selenium.UnhandledAlertException during execution of Click.on and the alert will not be present after this task. If the next task would be "interact with alert" in any way or form (as done in all the linked articles and all others I have perused before posting this question), the next task will then always fail because there is no alert .
This can be easily observed in the browser window as well: The alert may show, if at all, for but a split second and immediately disappear.
The question:
Given that the alert has to be handled before the action causing it completes: How do I do that?
N.b.:
I have done a deeper analysis in this old bug report. Includes a call stack where one may place breakpoints inbetween the alert's appearance and disappearance.
Others have indicated that it is an issue pertaining to chromedriver - but using a different framework with the same chromedriver works just fine.
A workaround might be to disable screenshots, but
I do not want to do that!
Serenity indicates (via a log warning) that this is a user error. So I'd rather correct my error than work around it.

Fixing Unsuccessful Transaction on Payment Gateway using Midtrans (Android)

So I recently just trying to understand deeper into Payment Gateway (Android). I already read the documentation and try to implement it into my Android project. So here's the thing, couple times even until now, I'm always getting a message "Transaction unsuccessful. Please try again with another card or with a different payment method" when I try to click a button called Pay. So this Pay button when I clicked it, it supposed to open a new tab (page) to show all of the Payment Method. But again that page never showed up, and showing those errors only.
Can anyone help me fixing this problem? I'm gonna send u guys the code if u guys need it. BIG THANKS :)
This is my button code looks like. How did I can get a page that showing PaymentUiFlow (Payment Method Page)? I already try to configure it out with many different ways but still showing the same error.
private void actionButton() {
MidtransSDK.getInstance().setTransactionRequest(DataCustomer.transactionRequest(
"1",
getIntent().getIntExtra("price", 0),
getIntent().getIntExtra("qty", 0),
getIntent().getStringExtra("name")));
MidtransSDK.getInstance().startPaymentUiFlow(ProductOrderActivity.this, PaymentMethod.BANK_TRANSFER_MANDIRI);
}

Selenium alert only shows in debug mode

I am testing a site page using Webdriver/Java which contains many fields. One of the fields is a dropdown box (or select box) and it contains validation upon losing focus (e.g. tabbing out). So if I select a particular option in the dropdown and tab to the next field, an alert box will pop up saying "You cannot choose that!".
Now I am doing code that checks for the presence of the alert box, and accepts it, however this is only working for me in DEBUG mode. When running the test (i.e. not in debug) I get "Timed out after 10 seconds waiting for alert to be present Build info: version: '2.53.0'".
I understand that this is probably a timing issue since it works in DEBUG mode, but I can't understand why as I'm using ExpectedConditions.alertIsPresent(). The code where this is failing is here:
WebElement currentElement = driver.findElement(By.id("selectbox"));
Select currentSelect = new Select(currentElement);
currentSelect.selectByVisibleText(updatedValue);
currentElement.sendKeys(Keys.TAB);
System.out.println("milestoneA");
if ((exceptionExpected()) {
System.out.println("milestoneB");
wait.until(ExpectedConditions.alertIsPresent());
System.out.println("milestoneC");
checkAlertBox(getExpectedResultFromExcel());
}
In DEBUG mode, the code keeps going fine and all is good. In RUN mode in my logs I get up to milestoneB and then the above mentioned error is thrown.
Further to this, if I add a Thread.sleep(1000) before Tabbing, all works fine.
Any ideas please?
I would try to send the TAB key until the element loses the focus:
WebElement currentElement = driver.findElement(By.id("selectbox"));
currentElement.click();
currentElement.sendKeys("abcd");
// wait for the popup to be visible
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#abc")));
// send the TAB key while the current element has focus
new WebDriverWait(driver, 20).until((WebDriver wd) -> {
currentElement.sendKeys(Keys.TAB);
return !wd.switchTo().activeElement().equals(currentElement);
});

Alternative to contextClick in Chrome: Selenium-WebDriver- Java

I know one can find similar question,but no one gave an alternate solution.Please bear with me.
After some research I realized it is not possible to automate contextClick in Chrome browser.For ex:
If I need to perform below code and browser has to be Chrome-
driver.get("https://www.google.com");
Actions ac= new Actions(driver);
ac.moveToElement(driver.findElement(By.id("hplogo"))).contextClick().sendKeys(Keys.ARROW_DOWN).build().perform();
It would be helpful if I can get an alternative to using contextClick options.
Thanks
On my chrome browser, contextClick is working fine. Try below line of code, it may resolve your problem.
ac.moveToElement(driver.findElement(By.id("hplogo"))).contextClick().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
Are you trying to do context click only, then
Actions conClick=new Actions(driver);
//i am expecting you are try to perform right click id = hplogo
conClick.contextClick(driver.findElement(By.id("hplogo"))).build().perform();
// if you want to select or click any option in this context menu
// go for click with specific location, no need of keys
// if required use sleep before click
driver.findElement(By.id("required location")).click();
if above click after context click is not working as expected, then you can also try below way
Actions conClick1=new Actions(driver);
//i am expecting you are try to perform right click id = hplogo
//after context click moving to 25 vertically, may be second option in context menu and clicking
conClick1.contextClick(driver.findElement(By.id("hplogo"))).moveByOffset(5, 25).click().build().perform();
Thank You,
Murali

How to submit searching field with android keyboard?

I have a problem with submitting searching field with android keyboard in Appium (selenium, java).I didn't find any working solution and stuck at this point. Please, help me.
I tried this:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Done\'].tap()");
But had an error:
org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)
You can't execute JS code that way in appium unless you are in a web view.
For hitting the search key, I would do it like this:
driver.sendKeyEvent(IOSKeyCode.ENTER);
You can send ENTER using:
driver.sendKeyEvent(66); // "66 - KEYCODE_ENTER
This link:
http://developer.android.com/reference/android/view/KeyEvent.html
will give you a list of all the Android KeyEvents, if you click on one of them you can see the actual code for it, like here:
http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_ENTER
Hope this helps!
If you are automating mobile web apps, then following is the best way to hide keyboard.
Map<String, Object> BackspaceKeyEvent = new HashMap<>();
BackspaceKeyEvent.put("key", "67");
((JavascriptExecutor)driver).executeScript("mobile:key:event", BackspaceKeyEvent);
This solution in JavaScript worked for me:
Java:
driver.executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));
Javascript:
await driver.execute('mobile: performEditorAction', { action: 'search' });
Notice: This special native api just worked for Android.
This allowed me to submit a search command (same as clicking the search icon in the keyboard).
See http://appium.io/docs/en/commands/mobile-command/ for details on "mobile: performEditorAction".

Categories

Resources