This is the code:
driver.get(url).then(function(){
txtFnn = driver.findElement(webdriver.By.xpath(xpath));
return txtFnn;
}).then(function(){
txtFnn.sendkeys("12345678");
})
Error:
TypeError: txtFnn.sendkeys is not a function
I'm assuming a lot because you don't supply much info, but from the code, I assume that driver.findElement returns a Promise ... so
driver.get(url).then(function(){
return driver.findElement(webdriver.By.xpath(xpath));
}).then(function(txtFnn){
txtFnn.sendkeys("12345678");
})
Does that work? If so, I'll explain where you went wrong in the first place, but if not, there's no point wasting time on explaining something comes from my assumptions
your code can be simplified as:
driver.get(url);
txtFnn = driver.findElement(webdriver.By.xpath(xpath));
txtFnn.sendkeys("12345678");
can you try this and tell me if you are still getting the error? are you sure that the xpath is correct?
Related
I have simple function that aims to log a user in via localstorage,
and then a second one that checks if the user can be found ( i need it separated because i need the logincheck elsewhere)
logInUser(user: IPerson): Boolean {
localStorage.setItem(this.userID, JSON.stringify(user));
return this.isUserLoggedIn();
}
isUserLoggedIn(): Boolean {
return Boolean(localStorage.getItem(this.userID));
}
But this code seems bad to me because im not actually verifying that logInUser did its job, im just calling another function for this.
I was thinking about converting this into a Promise of boolean and chain .then() but this doesnt work with setItem()
technically, setting something to a storage does not return anything, so i dont know how to verify correctly that it did and catch errors.
If it returns without exception you can assume it worked. If you really want you can double check it with localStorage.getItem(this.userID) === JSON.stringify(user) and that's the ultimate test.
Exception might occur if you try for example to setItem in a snippet in stack overflow.
TypeError: elem[prop] is not a function
E2E testing in webdriveio. I want to click a button inside an iframe.
let iframe = browser.$('#fullmessage')
browser.pause(1000)
browser.switchToFrame(iframe)
browser.setTimeout({ implicit: 10000 })
let clickAgree = $('a[class="button is-success"]')
clickAgree.click()
browser.switchToParentFrame()
browser.pause(3000)
I was facing same error and when debug more using REPL found that the issue could be due to 2 reasons:
selector is returning array of elements and so it was not able to call the method used.
the method being called on element does not supports.
For example with following code:
$('.some_class').$$('input').getValue();
was getting error - Uncaught Error: elem[prop] is not a function. Using $('.auto_test_class').$$('input')[1].getValue(); works. But its better to use some Id or xpath.
Hope this might be useful for someone facing same issue :)
Hi i faced with the same problem, but in async. The reason is that you need
to await already defined element as parameter:
get iframe() { return $('.iframe'); }
await browser.switchToFrame(await this.iframe);
Because switchToFrame works only with element, not with promise.
Maybe for someone it will be useful.
So when I try to read the variable on complete with papaparse i get the following error: TypeError: wpcc_results is undefined.
I really cannot see what is wrong with my code here:
$('.wpcc_gen_box_form').submit(function(event) {
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
$('#wpcc_csv_file').parse({
complete: function(wpcc_results) {
console.log(wpcc_results.data);
}
});
});
I think fresh eyes would really help here.
I appreciate any help.
The solution is in fact to define the complete function within the config. As that is where the parameters are actually passed. Answer was found here: https://github.com/mholt/PapaParse/issues/168
Is it possible to call $httpbackend.flush(); only if there are some pending request ?
So I will never get
Error: Unflushed requests: 1,2,3,...,n
Or
Error: No pending request to flush !
According to the documentation there's an $http.pendingRequests property you could use. Something like this would work:
if($http.pendingRequests.length > 0) {
$httpBackend.flush();
}
I'm not sure it s a terribly good idea, but that should do it.
I think You should organize your tests to not use any "if" inside test.
Why?
To keep it simple and easy to understand what is actually tested, "if" gives a way to pass test while it should fail.
Write separate test function to test case when no request are made to API.
Read about AAA (Arrange Act Assert) pattern in testing it will helps you.
If you do not "expect" any requests you could put the call to http.flush(n) in a try-catch block in ignore the exception.
http.whenGet(/* .. */).respond(/*..*/); // maybe implementation needs some data
service.doSomething();
try { http.flush(99); } // resolve all the possible requests my service might have to do
catch(e) {}
expect(service.isAwesome).toBe(true);
I have the following node.js files:
//test.js:
var hash=require('./hash');
var sys=require('sys');
sys.puts(hash.hash("asdf","asdf"));
and
//hash.js:
var exec=require('child_process').exec;
var sys=require('sys');
exports.hash=function(data,hash_type){
exec('pwd',function callback(error,stdout,stderr){
sys.puts(stdout);
});
}
When I do node test.js, I get the following output:
eamorr#Compaq6000:~/Desktop/simple-hash$ node test.js
undefined
/home/hynese/Desktop/nodejs-simple-hash
Why am I getting "undefined"??? I'm really stuck here...
Any help is greatly appreciated.
Many thanks in advance,
Change:
sys.puts(hash.hash("asdf","asdf"));
to just:
hash.hash("asdf","asdf");
You're outputting the return value of hash.hash, although since you didn't provide a return value, the language returns undefined, which is then outputted to the screen. You already output the result of the system command in the callback, so you don't need another sys.puts.
As a side note, you probably don't need to name that callback function callback.