Getting "Argument Invalid Exception Error" on using selenium for passing URL customized URL's to chrome driver - selenium-chromedriver

I have a text file which contains multiple random URL's.
Example: https://5SnczRo6sk3hWl=10pfmNzxmNZ7f.geVxQ25XIQ%ic/%2O.nrw
While sending it to chrome, for some urls I'm receiving mentioned error however for some it is working properly. (My aim is very simple: Send URL to browser ,check its output and then close the browser.)
PFB Code:
url = open ('URL_DB_new.txt','r')
url_rpt = url.read().split("\n")
for link in url_rpt:
driver = webdriver.Chrome(executable_path=r'D:\Software\chromedriver\chromedriver.exe')
print("link: ", link)
driver.get(link)
time.sleep(3)
driver.quit()
PFB Error:
Selenium Error
Any suggestion on how to handle this exception or remove it?

Related

Python capturing "HTTP status code" exception messages

I am having problems error handling code when deleting a file from box.com using Box API. The code establishes a connection to Box.com via JSON.
client.file(file_id=99999999999).delete()
When I run the command, the Box APIs uses HTTP status codes to communicate if a request has been successfully processed or not. This is what I see in PyCharm:
Error output
How do I use this error response (the red text in the bottom of the screen to handle errors so I can do something like this:
try:
client.file(file_id=xxxxxxxxxx).delete()
except 404:
print('error 404 occurred')
except 405:
print('error 405 occurred')
Thanks
#xaleel
I have tried this:
config = JWTAuth.from_settings_file(JSONFile)
client = Client(config)
try:
client.file(file_id=99999999999).delete()
except BoxAPIException as e:
print(e.status)
The error returned is:
Traceback (most recent call last):
File "C:\Temp\Box\Test\Test.py", line 20, in
except BoxAPIException as e:
NameError: name 'BoxAPIException' is not defined. Did you mean: 'BaseException'?
I have also tried "BoxException". Is this case sensitive? where can I look to see the correct possible name to use? Sorry I am not a programmer and really new to Python. I just set myself this challenge to learn!

Laravel + Vue Error in render: "SyntaxError: Unexpected token u in JSON at position 0"

I have a Laravel application with Vue js and until a while ago it was working perfectly. Now when I go to any page that uses Vue js this error appears: [Vue warn]: Error in render: "SyntaxError: Unexpected token u in JSON at position 0".
When I reload the page by clearing the cache (Control + Shift + R on Mac OS) it works again, but when I update without this command the error appears again.
PS: I didn't do any package updates for both laravel and npm, it just stopped working out of nowhere.
Try this in the console:
JSON.parse(undefined)
Here is what you will get:
Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at <anonymous>:1:6
In other words, your app is attempting to parse undefined, which is not valid JSON.
There are two common causes for this. The first is that you may be referencing a non-existent property (or even a non-existent variable if not in strict mode).
window.foobar = '{"some":"data"}';
JSON.parse(window.foobarn) // oops, misspelled!
The second common cause is failure to receive the JSON in the first place, which could be caused by client side scripts that ignore errors and send a request when they shouldn't.
Make sure both your server-side and client-side scripts are running in strict mode and lint them using ESLint. This will give you pretty good confidence that there are no typos.
Sometime it is becaseu of this let data = JSON.parse(this.response); so try to change it to
let data = JSON.parse(this.responseText);
I really did was change this.response to this.responseText

How to verify login text box validation error message using Selenium [duplicate]

This question already has answers here:
How to handle HTML constraint validation pop-up using Selenium?
(3 answers)
Closed 3 months ago.
URL- https://www.vtiger.com/begin-free-trial
Enter an invalid email address such as "abcde" and now click on Next Button. You will notice an error message which will appear for 4/5 seconds ( image below )
How can we verify this error message, I am not able to get xpath of this also.
The error message which you are referring is a validation message which is the outcome of Constraint API's element.setCustomValidity() method.
Note: HTML5 Constraint validation doesn't remove the need for validation on the server side. Even though far fewer invalid form requests are to be expected, invalid ones can still be sent by non-compliant browsers (for instance, browsers without HTML5 and without JavaScript) or by bad guys trying to trick your web application. Therefore, like with HTML4, you need to also validate input constraints on the server side, in a way that is consistent with what is done on the client side.
Solution
To retrieve the error message Please fill out this field. you need to:
Induce WebDriverWait for the desired element to be clickable.
Now, to extract the validationMessage and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
Code Block:
driver.get("https://www.vtiger.com/begin-free-trial/")
work_email = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='email']")))
work_email.send_keys("dggf")
print(work_email.get_attribute("validationMessage"))
Console Output:
Please include an '#' in the email address. 'dggf' is missing an '#'.
Using XPATH:
Code Block:
driver.get("https://www.vtiger.com/begin-free-trial/")
work_email = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='email']")))
work_email.send_keys("dggf")
print(work_email.get_attribute("validationMessage"))
Console Output:
Please include an '#' in the email address. 'dggf' is missing an '#'.
Reference
You can find a detailed relevant discussion in:
How to handle html5 constraint validation pop-up using Selenium?
Try Below Code -
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
action = ActionChains(driver)
driver.get('https://www.vtiger.com/begin-free-trial/')
driver.find_element_by_name('email').send_keys("xyz")
driver.find_element_by_xpath('//button[contains(text(),"Next")]').click()
messagetoVerify = "Please include an '#' in the email address. 'xyz' is missing an '#'."
myValidationmsg = driver.find_element(By.NAME, 'email').get_attribute("validationMessage")
if myValidationmsg == messagetoVerify:
print("Verified Validation Message")
Output -
Please include an '#' in the email address. 'xyz' is missing an '#'.

Box Server file upload error while using a QT application coded using the new OAuth2 API

I have been working on a Box App using the API v2 for the past few days and have successfully authenticated using OAuth2.
My app retrieves the access token successfully and I'm also able to access my Box account using the access token, however an upload of a file fails with a response of 299.
The html response I see from Box after posting an upload request has the following message
"Sorry, we can't access that page."
Your Box account may be temporarily unavailable. We're working on resolving the issue and should be back up soon."
I take it all 2xx errors mean that the request has been accepted but the Box server cannot handle it.
Given below is a snippet of my code used to post the file.
Any tips on what could be wrong is appreciated
I am following instructions from
http://developers.box.com/get-started/#uploading-and-downloading
QUrl requrl = QUrl("https://www.box.com/api/2.0/files/content");
std::string token = m_acc_token;
QString hdrval = "Bearer "+QString(token.c_str());
QNetworkRequest qnr(requrl);
qnr.setRawHeader("Authorization",hdrval.toUtf8());
QString boundary;
boundary = "---------7d935033608e2";
QByteArray data;
data.append("file=#btest.txt");
data.append(boundary);
data.append("folder_id=0");
data.append(boundary);
qnr.setHeader(QNetworkRequest::ContentTypeHeader,"multipart/form-data; boundary=---------7d935033608e2");
qnr.setHeader(QNetworkRequest::ContentLengthHeader,data.size());
QNetworkReply* areply = NULL;
areply = m_networkManager->post(qnr,data);
you can implement it like
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart headerPart;
headerPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"parent_id\" \" "));
headerPart.setBody(QString(aParentFolderId).toLatin1());
QHttpPart textPartData;
textPartData.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; filename=\"filename\" \" "));
textPartData.setBodyDevice(&File); //file must be open.
File.setParent(multiPart);
multiPart->append(headerPart);
multiPart->append(textPartData);
QNetworkRequest networkReq;
networkReq.setUrl(QUrl("https://upload.box.com/api/2.0/files/content"));
networkReq.setRawHeader("Authorization", "Bearer " + AccessToken.toLatin1());
networkReply = mNetworkAccessManager.post(networkReq, multiPart);
multiPart->setParent(networkReply);
The curl call in the Box API documentation can't be translated directly to code as you have done. the file=#btest.txt line on the command line puts the contents of file btest.text as the value of the parameter file.
Additionally, your multipart boundaries are malformed: they must end in \r\n; one must be present at the start of the multipart body, and another boundary with a slightly different format must be present as a final boundary. If you are interested in manually implementing the multipart form data, I'd recommend reading RFC 1876.
The Box API will return a 500 response if it is sent a malformed multipart POST body.
I'd recommend using QHttpMultiPart, for multipart form uploads, which is part of the Qt framework.

Using Ext JS with my HTML Files

I have an application uses Spring Security 3(has a Jackson Marshaller) runs on a Tomcat 7. I designed my application with Jquery and it runs well. I designed a login page with Ext JS and after successful login it redirects to index.html. However it gives an error and can't redirect because when server sends HTML file it comes into that function at Ext JS:
Ext.util.JSON = new (function(){
...
doDecode = function(json){
return eval("(" + json + ")");
},
...
I wants to render it as a JSON response and gives an error as usual. How to solve it?
PS: It gives that on Firebug:
syntax error
[Break On This Error] (<!DOCTYPE html>
The server is not returning valid JSON. Its look as if it is returning a HTML page (perhaps a friendly error page). If you follow the stack trace up its probably Ext.decode response.responseText (inspect this you'll see whats returned although not the best way)
First step would be to investigate the request in the Net panel in Firebug or Chrome, look at the request and response headers and content this will point you in the right direction. Please please please do not resolve this problem without first learning to use a client side browser debugger (Firebug or Chrome Dev Tools or even Safari) such as walking the stack on break on error, break on XHR, inspect the XHR headers and response etc.. not just watching the console window.
You might be able to fix this continuing blind but you'll pay heavily again next time.