I have spent some hours trying to search an element by id using appium javascript client with no luck. Have found some other posts here in stack overflow stating it works, but it doesn not work for me. It seems that I could use something like:
var buttonEl = await driver.findElement(By.id("resourceid"));
but I always get an error saying:
InvalidSelectorError: Locator Strategy 'css selector' is not supported for this session
Here the source code:
"use strict";
var wd = require("selenium-webdriver"),
By = wd.By,
until = wd.until;
// Setting Desired Capabilities.
var desiredCaps = {
platformName: "Android",
deviceName: "a3ae1c63",
appPackage: "com.mypackage",
appActivity: ".Main",
browserName: '',
noReset: true,
newCommandTimeout: 1000000
};
async function test() {
//Initiating the Driver
let driver = await new wd.Builder().usingServer("http://localhost:4723/wd/hub").withCapabilities(desiredCaps).build();
var buttonEl = await driver.findElement(By.id("id/contact_selector"));
buttonEl.click();
}
test();
I'm pretty confused now. I understand that it seems that I can't use the find element by id in an android session but on the other hand I have read about people using it successfully.
Any help would be greatly appreciated.
I think you are using selenium arguments for the locator strategy. Please readedocumentation of appium selector here http://appium.io/docs/en/commands/element/find-elements/index.html#selector-strategies.
try this
var buttonEl = await driver.element("id", "resource-id");
Finally I was able to fix my problem. The main problem was that I wasn't using the needed web driver. I switched to webdriverio and everything is working now.
Better place to start is to check examples in appium github. They have some examples for every driver. Code is a bit outdated though.
Related
I write this code to check if on my website is a text and if its not then it should send me a notification thru slack. When I run it on VSC it crushes after some time like maybe 15 min or something like that.
I want to make it nice to put it on a server and run it remotly but need to be sure that will not crash every so often. I want to use it to check some websites for changing information on them and if they will change or be gone then send me notification. Best bit it works but crashes and don't know why :(
Can someone maybe help or pinpoint what it can be the problem? It will be better that this tool can just see text instead of class but I don't know how to do that.
//Puppeteer library
const pt= require('puppeteer')
const axios = require('axios')
process.setMaxListeners(0);
async function getText(){
//launch browser in headless mode
const browser = await pt.launch()
//browser new page
const page = await browser.newPage()
//launch URL
await page.setDefaultNavigationTimeout(0);
//website
await page.goto('https://mieciusio.pl/kontakt.html')
//identify element
if (await page.$("[class='p-style btn-resize-mode label-bloc-2-style label-1-style']"))
console.log("found")
else //console.log("not found")
axios.post(' https://hooks.slack.com/services/MYUniqeID', {text: 'Its changed'})
}
setInterval(getText, 12000)
Try to find it online on YT but it's hard I was looking in a lot of tut's but can't find right one to work on finding text on website or not to crush because I don't know why crashes.
We had not done any recent upgrades.
We are trying to run this javascript code (createpdf.js)
const puppeteer = require('/home/glossyadmin/node_modules/puppeteer');
const InvoiceNumber = process.argv[2];
const PDFdir = __dirname + '/../email/invoice/';
(async () => {
const browser = await puppeteer.launch({args: ['--no-sandbox']});
const page = await browser.newPage();
await page.goto('http://localhost:8080/admin/ajax/invoice?InvoiceNumber=' + InvoiceNumber + '&Print=Print', {waitUntil: 'networkidle2'});
await page.pdf({path: PDFdir + InvoiceNumber + '.pdf', format: 'A4'});
await browser.close();
})();
We have been calling the code above with this PHP script:
$Vars = json_decode(urldecode(#$argv[1]), true);
$InvoiceNumber = $Vars['InvoiceNumber'];
$createScript = $_SERVER['DOCUMENT_ROOT'] . '/admin/workers/createpdf.js';
exec("node $createScript 2>&1 ".escapeshellarg($InvoiceNumber), $arrayReturn);
It has been working but lately it just stopped. The code seems good (no PHP errors in the error log) but it just is no longer calling / executing the createpdf.js script. And we have verified that node is in fact installed.
We have not upgraded PHP, Node, or any other updates. We've tried changing permissions of files and directories. Nothing changes. Slamming our head into a wall here.
After continuing to dig and finding out more and more people were having this issue with little to no fixes. I found another thread on stackoverflow that talked about somebody that had upgraded their version of puppeteer and it suddenly stopped working.
We had not done any upgrades to puppeteer, node, or the system at all but still wasn't working. I took the very simple advice in the comments of this thread: Puppeteer script suddenly stopped working after upgrading Puppeteer
Delete the entire node_modules directory and reinstall puppeteer.
Not sure why exactly but it has worked. I wish there was more information out there. Luckily it's a quick install.
To develop an algorithm I used TurfJs library to avoid to do some calculations my self, and I have been asked to integrate the algorithm to an Eclipse Vert.x server, in which I'm new.
So I tried to import it directly like usual: var turf = require("#turf/turf");
and when I execute using this command: ./node_modules/.bin/vertx run server.js, I get this error:
Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 2762 ms, time limit is 2000
javax.script.ScriptException: TypeError: Cannot redefine property "name" of function IndexOutOfBoundsException (message) {
Error.call(this);
this.message = message || '';
} in node_modules/#turf/turf/turf.js at line number 26251
Here is server.js code if needed:
var Router = require("vertx-web-js/router");
var turf = require("#turf/turf");
var server = vertx.createHttpServer();
var router = Router.router(vertx);
router.get("/").handler(function (ctx) {
var response = ctx.response();
response.putHeader("content-type", "application/json; charset=utf-8");
response.end("[\"foo\",\"bar\"]");
});
server.requestHandler(router.accept).listen(8080);
Note: here I haven't yet used turf, because just importing it causes the above problem.
Please help, Is it possible to use Javascript/nodejs library in Vert.x ?
So I'm answering my question, after a lot of searches I ended that the problem is with TurfJs which is deprecated from turf to #turf/turf according to this link
so I tried to to use turf rather than #turf/turf, and it works even it show this message:
Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 2627 ms, time limit is 2000
Succeeded in deploying verticle
I have a basic piece of javascript that I am running from a .js on a windows desktop to retrieve data from https://lookup.binlist.net/ - when I run it I get a timeout on the GET line. I have looked at various solutions and not found anything that resolves my issue. Anyone got any ideas?
var urlb = "https://lookup.binlist.net/431940";
var xsh = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
xsh.open("GET", urlb, false);
xsh.send();
I need to be able to run phantomjs with the following arg:
--ignore-ssl-errors=true
The page I'm testing uses a self-signed cert so I need the arg to open the page. I'm trying to pass the arg in webdriver using the snippet below:
capabilities = webdriver.Capabilities.phantomjs();
capabilities.set('service_args', '--ignore-ssl-errors=true');
driver = new webdriver.Builder().
withCapabilities(capabilities).
build();
Is the correct way to pass the service_args? I actually hope not since I can't load my test page. I can open the page by running:
phantomjs --ignore-ssl-errors=true myTest.js
Here is the code in myTest.js
var page = new WebPage();
page.open('https://my.somefaketestpage.com/', function (status) {
just_wait();
});
function just_wait() {
setTimeout(function() {
page.render('screenshot.png');
phantom.exit();
}, 2000);
}
The correct answer is:
caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
driver = new PhantomJSDriver(caps);
documented here: https://github.com/detro/ghostdriver/issues/233
In case someone will need it for facebook/php-webdriver CLI arguments can be passed to PhantomJS in a following manner:
$driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', [
WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::PHANTOMJS,
WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY,
'phantomjs.cli.args' => ['--ignore-ssl-errors=true']
]);
Reading this I got really confused, as the accepted answer is in Java, and the GhostDriver constants and stuff aren't present. For those who are also confused, this worked for me:
var webdriver = require('selenium-webdriver'),
Capabilities = webdriver.Capabilities;
var capability = Capabilities
.phantomjs()
.set('phantomjs.cli.args', '--ignore-ssl-errors=true');
var driver = new webdriver
.Builder()
.withCapabilities(capability)
.build();