Scroll issue in android native app - javascript

I am using appium and java to automate my app. I need to scroll in a page till a specific text/Element. I am struggling since two days and have tried many solutions but it dint work. Listing down all the solutions and scenarios:
Appium version: 1.4.0
Java-client version : 4.1.2
Driver: RemoteWebDriver
Solution1.1:
Tried with Java Script. Here is the code:
JavascriptExecutor js = (JavascriptExecutor)driver;
HashMap scrollObjects = new HashMap();
scrollObjects.put("direction", "down");
scrollObjects.put("text", "Yes");
js.executeScript("mobile: swipe", scrollObjects)
Solution 1.2:
WebElement wb = driver.findElement(By.xpath("//*[#resource-id = 'com.practo.fabric:id/toolbar']/following-sibling::android.widget.LinearLayout"));
JavascriptExecutor js = (JavascriptExecutor)driver;
HashMap scrollObjects = new HashMap();
scrollObjects.put("direction", "down");
scrollObjects.put("text", "Yes");
scrollObjects.put("element",wb);
js.executeScript("mobile: swipe", scrollObjects);
Problem here is i dont have list view. I have linear layout so have tried with providing linear layout xpath also once but with no luck.
Solution2:
org.openqa.selenium.Dimension size =driver.manage().window().getSize();
int starty = (int) (size.height * 0.80);
int endy = (int) (size.height * 0.20);
int startx = size.width / 2;
driver.swipe(startx, starty, startx, endy, 3000);
System.out.println("swiping is done ");
Here driver.swipe is giving error as i am RemoteWebDriver. When i try to use AndroidDriver it says deprecated.
what should i do in this situation?

You are facing issue because of the appium server and java client library version mismatch. Kindly update appium server to 1.5/1.6 else you can use java-client library version 2.1.0.
If you choose to use java-client2.1.0 with appium 1.4 we are having a method named "scrollTo" which scrolls to a particular text. I have also used "swipe" as you mentioned in solution 2 in this combo.
driver.scrollTo("Like"); //Scrolls to Like text in the app

I got it solved by using AppiumDriver from java-client. As i am using latest java-client version (5.0.0-BETA6) it says "swipe" methos is deprecated. but it works.
driver.swipe(300, 701, 300, 441, 3000);
solved it using TouchAction class also.
TouchAction action = new TouchAction(driver);
action.press(300, 701).waitAction(2000).moveTo(300, 441).release();
action.perform();
Note: coordinates are hard coded.

Related

Win32 NodeJS - Get Icon from running Window

I try to get a list of active windows currently running in Windows 10. The same list as the alt+tab window shows. this is working find, but I also need the icons of these windows. Unfortunately this is not working. The following code returns a pointer which should be an hicon. But I have no idea how to interpret the hicon. How can I translate this to an image?
const user32 = new ffi.Library('user32', {
'SendMessageA': ['pointer', ['long', 'int32', 'long', 'int32']]
});
let WMessages = {WM_GETICON: 0x007F}
let hicon = user32.SendMessageA(hwnd, WMessages.WM_GETICON , 2, 0)
// how to translate hicon to an nodejs icon?
this logic is inside an EnumWindows loop but I cut it, since it is not of relevence for my issue.
I am using ffi-napi and ref-napi to make native library call.
Any help is appreciated,
thanks

how to make safari browser in full screen while running automation test

I am using java + selenium webdriver for webautomaiton.
For safari browser 10.1 version, I need the browser to be full screen before test started.However
driver.manage().window().maximize();
does not work
I tried few options but no luck.
1.
seems no option available for doing something like which would write in the plist file of /Library/Preferences folder of mac
defaults write com.apple.Safari
2
WebElement element = Wait.wait.until(visibilityOfElementLocated(By.cssSelector(".logo-large")));
element.sendKeys(Keys.CONTROL , Keys.COMMAND , "f");
element.sendKeys(Keys.CONTROL , Keys.COMMAND , "F");
Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL).keyDown(Keys.COMMAND).sendKeys("F").perform();
action.keyDown(Keys.CONTROL).keyDown(Keys.COMMAND).sendKeys("f").perform();
Is there anyway I can do it using send keys, or write in the plist file or through javascript.
Try below :-
public static void maximizeScreen(WebDriver driver) {
java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Point position = new Point(0, 0);
driver.manage().window().setPosition(position);
Dimension maximizedScreenSize =
new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
driver.manage().window().setSize(maximizedScreenSize);
}
Hore it will help you
Take a look here (Native Fullscreen JavaScript API): http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
Sample:http://johndyer.name/lab/fullscreenapi/
You have to update the safari browser, update the browser with Safari 11+ version
then you are able to maximize it using this code:
driver.manage().window().maximize();

JMeter - WebDriver Sampler - waitForPopUp

I am trying to work out a comparable command to use in jmeter webdriver sampler (JavaScript) how to do a waitForPopUp command. There must be a way. I have something that works for waiting for an element, but I can't work it out for a popup.
Update
I am using this code for waiting for an element:
var wait = new support_ui.WebDriverWait(WDS.browser, 5000)
WaitForLogo = function() {
var logo = WDS.browser.findElement(org.openqa.selenium.By.xpath("//img[#src='/images/power/ndpowered.gif']"))
}
wait.until(new com.google.common.base.Function(WaitForLogo))
And this works, but I can't work out how reuse this to wait for a popup, that has no name, in Java I have used:
selenium.waitForPopUp("_blank", "30000");
selenium.selectWindow("_blank");
And that works, but I can't work out an comparable JavaScript that will work in Jmeter for performance, as I can't get Java working in Jmeter.
I was able to get this working using:
var sui = JavaImporter(org.openqa.selenium.support.ui)
and:
wait.until(sui.ExpectedConditions.numberOfWindowsToBe(2))
In WebDriver Sampler you have the following methods:
WDS.browser.switchTo.frame('frame name or handle') - for switching to a frame
WDS.browser.switchTo.window('window name or handle') - for switching to a window
WDS.browser.switchTo.alert() - for switching to a modal dialog
WDS.browser.getWindowHandles() - for getting all open browser window handles
See JavaDoc on WebDriver.switchTo method and The WebDriver Sampler: Your Top 10 Questions Answered guide for more details.

Selenium/VBA/Javascript: Trigger Mouse Event

I have some Webdriver (java) code that I am looking to translate to VBA. The code is as follows:
WebElement pos1 = LiloTest.driver.findElement(By.id("autoAssocitionForm:categoryDetailCombinationId:23"));
JavascriptLibrary jsLib = new JavascriptLibrary();
jsLib.callEmbeddedSelenium(LiloTest.driver,"triggerMouseEventAt", pos1,"click", "0,0");
I am trying to run the equivalent in VBA, utilizing the Selenium type library, but I am not quite sure how to make it work. I have tried using the "ExecuteScript" method, but have not had much luck. Part of the problem is that I can't see any javascript when looking at the page source, etc., for the element in question.
Any assistance would be greatly appreciated.
I was able to figure it out:
JsTest = "document.getElementById('autoAssocitionForm:categoryDetailCombinationId:23').checked = true;"
Set Pos = bot.FindElementById("autoAssocitionForm:categoryDetailCombinationId:23")
Pos.ExecuteScript (JsTest)

Unable to sendkeys using webdriverjs specifically F11 to maximise the browser

With the below code block it opens a chrome browser fine it just won't full screen the browser using F11. i used to use C# and selenium and that worked fine using this method on chrome and different browsers. It finds the element 'body' but then does not send the key press. Am I doing something wrong here that i should be requiring some other library?
the documentation for webdriverjs is pathetic and there is very few examples, I am seriously considering dumping it for something else possibly python.
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('https://www.google.co.uk/');
driver.wait(function () {
return driver.getTitle().then(function (title) {
return title === 'Google';
});
}, 1000);
driver.findElement(webdriver.By.xpath('/html/body')).sendKeys("F11");
why are we doing this. we are developing a website that will change depending on size 800x600 + with and without the toolbar depending on how the screen is used different items will be displayed. i can maximise the window using,
driver.manage().window().maximize();
This however still leaves the toolbar present and doesn't act as if the user has pressed the F11 key.
it tooks some time to find it but you should have all the Keys in webdriver.Key
driver.findElement(webdriver.By.xpath('/html/body')).sendKeys(webdriver.Key.F11);
Hope it helps!
A co-worker has just discovered that it works well in C# with:
Driver.Instance.Manage().Window.FullScreen();
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).send_keys(Keys.F11).perform()
I use a similar command to toggle JS via Firefox's NoScript add-on
edit: I just tested, and it works!
This should work for you:
driver.findElement(webdriver.By.xpath('/html/body')).sendKeys(Keys.F11);
You can maximise the window using:
driver.manage().window().maximize();
For me the one emulating correctly the F11 on startup is:
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);
Or if the kiosk mode is preferred:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
WebDriver driver = new ChromeDriver(options);

Categories

Resources