Testing chrome webstore using WebdriverJS - javascript

I'm facing problems by testing the chrome webstore - using WebdriverJS and my own node.js script.
When trying to query the result using css selectors, I get allmost everytime "no such element" errors from the WebDriver Server.
var client = require('webdriverjs').remote();
client.init().url('https://chrome.google.com/webstore',function(result{console.log(result);})
.setValue('#searchbox-input','sampleapp \n')
.click('**?what should be here?**', function(result){console.log(result);}).end();
I'm struggling with the part - ?what should be here? so i can automate clicks on a displayed result.
CSS selectors have strange formats and can't be accessed.

Since the chrome webstore doens't seem to have button to click and submit the search, you could, instead, send the carriage return character and get it to trigger the search result.
Try something like this:
var client = require('webdriverjs').remote();
client.init()
.url('https://chrome.google.com/webstore')
.setValue('#searchbox-input','sampleapp \u000D')
.end();
The "\u000D" is just a carriage return unicode code.

Related

Sending keys via Selenium to Google Auth fails (using Python and Firefox)

I am following a Django Tutorial by Marina Mele, which is pretty good but a bit outdated since it was last updated in 2016, I believe. I am now trying the Selenium testing and ran into the problem that I can send my e-mail address via Selenium but not the password. My code is
self.get_element_by_id("identifierId").send_keys(credentials["Email"])
self.get_button_by_id("identifierNext").click()
self.get_element_by_tag('input').send_keys(credentials["Passwd"])
self.get_button_by_id("passwordNext").click()
with these functions being defined as:
def get_element_by_id(self, element_id):
return self.browser.wait.until(EC.presence_of_element_located(
(By.ID, element_id)))
def get_element_by_tag(self, element_tag):
return self.browser.wait.until(EC.presence_of_element_located(
(By.TAG_NAME, element_tag)))
def get_button_by_id(self, element_id):
return self.browser.wait.until(EC.element_to_be_clickable(
(By.ID, element_id)))
Most advices that I read to this issue circled around waiting until the element appears. However, this is covered through these functions. And I am using by_tag since the current version of Google Authentication is using an input for the password field that has not an ID but is a div/div/div child of the div with the "passwordIdentifier"-id. I have also tried using Xpath but it seems that this does not make a difference.
Also, it seems like Selenium is capable of finding the elements...at least when I check with print commands. So, locating the element seems not to be the problem. However, Selenium fails to send the keys from what I can see when I look at what happens in the Firefox browser, while Selenium is testing. What could be the issue? Why is Selenium struggling to send the password keys to the Authentication form?
Thanks to everyone in advance!
When you search an input on google registration page, you will find 8 WebElements. I think it is the origin of your problem.
I would use another localizer such as an xpath = //input[#name='password'] or a By on the name instead of the tag name, as implemented below:
def get_element_by_name(self, element_tag):
return self.browser.wait.until(EC.presence_of_element_located(
(By.NAME, element_tag)))
and:
self.get_element_by_id("identifierId").send_keys(credentials["Email"])
self.get_button_by_id("identifierNext").click()
self.get_element_by_name('password').send_keys(credentials["Passwd"])
self.get_button_by_id("passwordNext").click()

Aw, snap error in chrome while insert value into web sql using executeSql

I am creating a sqlite editor for android application, it is execute correctly still yesterday and finally just I tried to backup the chrome websql db so just copy the files from the following path "C:\Users\merbin.SERVER\AppData\Local\Google\Chrome\User Data\Profile 1\databases" and "C:\Users\merbin.SERVER\AppData\Local\Google\Chrome\User Data\System Profile\databases". Today I got the Aw, snap error on chrome, I debug the error and found, the error occur when I trying to create a table or inserting data into the database. But select query is execute perfectly. Some code examples are
query="insert into tbl(Type) values('Test')";
insert_query(query,insert_success,insert_fail);
function insert_query(query,succ_fun,fail_fun)
{
db.transaction(function(tx,result)
{
tx.executeSql(query, [],
function(tx,result)
{
eval(succ_fun)(result)
});
},eval(fail_fun));
}
function insert_success(result)
{
debugger;
$("#ex_area").empty();
$("#ex_area").append(result.rowsAffected+" Row(s) Affected.<br> Last Inserted ID is "+result.insertId);
alert("Insert Success");
return false;
}
function insert_fail(result)
{
debugger;
$("#ex_area").empty();
$("#ex_area").append("<span class='error'>"+result.message+"<br> Code : "+result.code+"</span>");
}
After that "eval(succ_fun)(result)" line I getting the Aw, snap error. screenshot is shown below.
image 1 Error on the Next Line Execution Screenshot
image 2 From previous line I am getting this error
Note : I think after update the chrome I have this problem.
I have solve this problem running the code through localserver. First the chrome allow to access the websql without using any server, but recent update chrome has change that rule. So must need any local server like xampp,wamp,IIS or etc...
by running the code through localserver: your JavaScript hosted through local server or the database or both
Create a new Google Chrome shortcut on your desktop.
Right click it, then click properties.
Add -allow-file-access-from-files to the end of the Target.
The end of the target should look like this:
\chrome.exe" -allow-file-access-from-files
Go into Task Manager.
Click Details.
End every single chrome.exe which is running.
Open up Google Chrome using the new shortcut you created.
Open up your website which uses WebSQL.
This worked for me.
Warning:
-allow-file-access-from-files lets Google Chrome have access to all of the files on your computer. ONLY, ONLY use this shortcut for developing. Do not browser the web, especially to untrusted websites, while you have this feature activated.
To deactivate it:
Go into task manager and end all chrome.exe's then open up chrome with a normal shortcut.

Where is Chrome's debugger console command history stored?

I often use Chrome's debugger console for experimenting with javascript code fragments. When I got it right I usually want to copy the needed commands into my script, but here is where it gets messy. The is no filter options for commands and no way to call certain commands back (like with Ctrl-R in Bash) so you need to step through all the commands in the history and copy the commands you want one by one.
Instead, I think it should be possible to retrieve the command history from some file or Sqlite database. But I can't find it.
So my question is: Where is Chrome's debugger console command history stored?
I found an answer here: How to access firefox web console command history?
I had some trouble getting it working, but here is how I did.
Open the developer console (shift-ctrl-I). Then open that console in a new window if it isn't that already by using the menu in the upper right (the three dots).
When it is a separate window, press shift-ctrl-I again. Then paste something like this:
var hist = JSON.parse(localStorage.consoleHistory);
hist.forEach(function(command){
console.log(command);
})
Now, with all the commands in the console you can either copy them all to the clipboard or use the filter field above the console to do some filtering on them (you can use regex).
https://code.google.com/p/chromium/issues/detail?id=171386
Seems there was talk of such a feature which never came to fruition
You can collect some people and pressure the devs to put it in, or get it done.
Sounds really useful to me (:
For retrieving history :
https://developer.chrome.com/extensions/experimental_devtools_console#method-getMessages
How about developing an extension around that ?
Adding To marlars answer :
Actually i think its a little useful to not convert it into json. you can just keep it as a string so that you can use .indexof('yoursearchvalue')
And you don't have to always type that piece of code. you can just go to the Application tab -> Local Storage -> Devtools Entry and click on the consoleHistory

Can I prevent the Chrome Developer Tools console from logging image 404 errors? [duplicate]

This question already has answers here:
Suppress Chrome 'Failed to load resource' messages in console
(3 answers)
Closed 5 years ago.
The Chrome Developer Tools console logs an error each time a page asset (including an image) isn't found (i.e. returns 404).
In my work, I'm often working on sites where images are provided by third parties and may not be available during development. Having each missing image show up as an error in the console makes other more important errors (e.g. JavaScript errors) harder to notice.
Is there a setting that stops the console logging unfound images as errors?
Or is there some way to filter console messages by the same sort of criteria that you can filter requests by in the Network tab?
(See e.g. http://chromium.googlecode.com/issues/attachment?aid=1337330000000&name=Screenshot-Google%2B+-+Google+Chrome.png&token=1F05er8uKjAQEEBrUITFjsIGJ2A%3A1358867878658&inline=1)
Work has "started" on this by the Chromium team: https://code.google.com/p/chromium/issues/detail?id=96212
Update: The feature request was closed on March 18, 2013. I'm not sure in which version of Chrome this feature first appeared, but I can confirm console filtering options in my Chrome v33.0.1750.152 (Linux).
Update 2: Currently, when a filter (plain text or regular expression) is entered, it is tested against the message text (e.g. GET http://example.com/foobar 404 (Not Found)) as well as the text of the right side link (e.g. test.html:65). (I have filed an issue with Chromium to track this.)
As a workaround, use a regular expression filter like:
^(?!.* 404 \(Not Found\))(?!.*[file name])
where [file name] is the file name from the right side link.
For example, if my page is test.html, then ^(?!.* 404 \(Not Found\))(?!.*test\.html) will work.
Note: This will also filter out messages that have the file name in the message text. I'm not sure there is a way around this for now.
Update (2019-06-05): This expression will filter out 404s in my current version of Chrome (75.0.3770.80):
-/404\s\(Not\sFound\)$/
It seems the filtering first splits the filter string by whitespace before processing each token, but it will also split spaces inside of a regular expression, so the \s's are necessary.
Technically, this will filter out any message ending with the (case insensitive) string "404 (Not Found)", including console.log messages.
In the chrome developer tools, it's under the "Console" tab. Click "Filter" and it will be on the filter line as a checkbox.
As an alternative answer you could run a bit of javascript to alter the src attribute of the offending images when on your dev server (just make sure you don't publish it to your production environment!).
If you don't want to actually add javascript to the page (understandably) you could probably run the script on load of the page via a chrome plugin (perhaps the greasemonkey chrome clone - tampermonkey).
n.b. Thanks for the feedback, notably for this to work it'll need to be within an event after the dom is ready and before the images load.
In your app, in your 'catch' statement.. log the exception under 'console.warn' .. know it works with firebug. In Firebug, you can then find these 'errors' under the 'warnings' tab. I would like to think the same can be true for Chrome Developer Tools..
actually did something similar day ago.. my app would stop on some error, so, I instead used the 'try' and 'catch' block. My catch looks like:
catch (e) {
console.warn(e);
}

How to write all javascript/Jquery exceptions to one text file?

I want to log/write all javascript errors to one text file when ever an error happens in my JavaScript functions or jQuery plugins.
For eg. PHP page call fails, undefined var.. etc. like errors happens I need to write it on a text file.
How can I do that. Please help me.
You can use console.log for logging after installing firebug
https://getfirebug.com/
Dependes on witch browser you are using:
> Firefox? - Look at firebug http://getfirebug.com/
> Chorme? - Right Click > Inspect element
> Safari? - Preferences > Advanced > Show develop menu in menu bar
> IE? - To complicated download another browser. :)
And then use console.log(...);
Whenever I get errors in javascript I make a call to my "LogError" function which passes the error data to a web service which can then log it on the server or email it off or whatever you need.

Categories

Resources