Python - Form is filled but not sent - python

I've been trying to submit a form using requests and urllib (separately), but without much success.
Printing the response shows the relevant fields are actually filled, but the form is not sent.
Here's the code python i've used (the form_data and url were changed of course)
import urllib
import urllib.request
import urllib.parse
import requests
form_data = {'username':'amiti9124#gmail.com',
'pass':'123456',
'passC':'123456',
'Fname':'amitiamiti',
'Tkav':'039111111',
'Cname':'abc',
'Creditme':'2',
'numberOfFaxes':10,
'faxNumber1':'039555555'}
url = "www.someurl.com"
req = requests.post(url,form_data)
print(req.content.decode('UTF-8'))
EDIT:A PART OF THE OUTPUT IS ALSO ADDED
<form action="" method="POST">
<div id="menues">פרטי מנוי</div>
<div id="titles"><font color="red" >*</font> כתובת מייל :
<br />
<input id="inputs" type="text" class="" dir="ltr" style="text-align:left; direction: ltr;" name="username" value='amiti9124#gmail.com' />
</div>
<div id="titles"><font color="red" >*</font>סיסמה :
<br />
<input id="inputs" type="password" class="" name="pass" dir="ltr" style="text-align:left; direction: ltr;" value=123456 />
</div>
<div id="titles"><font color="red" >*</font>אימות סיסמה :
<br />
<input id="inputs" type="password" name="passC" class="" dir="ltr" style="text-align:left; direction: ltr;" value=123456 />
</div>
<div id="titles"><font color="red" >*</font>שם מלא :
<br />
<input id="inputs" type="text" name="Fname" class="" value='amiti amiti' />
</div>
<div id="titles"><font color="red" >*</font>טלפון :
<br />
<input id="inputs" type="text" name="Tkav" class="" dir="ltr" value='039111111' />
</div>
<div id="titles">שם חברה (לחשבונית) :
<br />
<input id="inputs" type="text" name="Cname" value='abc' />
</div>
<div id="titles" class="paidOrTrial">
<input type="radio" id="Creditme" name="Creditme" value="1" style="width: 20px; height: 20px; vertical-align: middle;" />
המשך לתשלום בכרטיס אשראי.
<br />
<input type="radio" id="trialAccount" name="Creditme" checked="checked" value="2" style="width: 20px; height: 20px; vertical-align: middle;"/>
בקשת יתרת התנסות/חשבון נסיון
</div>
<div id="titles" style="display: none; padding: 5px 0 5px 0;">כמות פקסים צפויה לחודש:
<input type="number" id="numberOfFaxes" name="numberOfFaxes" min="0" max="300" step="10" style="width: 40px;" value='10' dir="ltr"/>
<div id="err_msg_number" style="display: none; color: red;"></div>
</div>
<div id="numberOfFaxesWrapper" style="display: none;">
<div id="titles" style="padding: 10px 0px;">חשבון ההתנסות יאפשר שליחת פקסים ל 3 המספרים הבאים :</div>
<div id="titles">מספר פקס 1 :
<br />
<input id="inputs" class="" type="text" name="faxNumber1" dir="ltr" value='039555555' />
</div>
<div id="titles">מספר פקס 2 :
<br />
<input id="inputs" class="" type="text" name="faxNumber2" dir="ltr" />
</div>
<div id="titles">מספר פקס 3 :
<br />
<input id="inputs" class="" type="text" name="faxNumber3" dir="ltr" />
</div>
</div>
<input type="submit" name="Button2222" value="הרשם" style="margin: 6px 0pt; padding: 0px 5px; font-size: 130%; font-weight: bold; color: rgb(0, 0, 0);">
</form>
I'd be grateful if anyone could point me to the solution.
Thanks in advnace !

Try using
req = requests.post(url, data=form_data)
Without the keyword you have little idea which parameter your data argument is being associated with, but it's probably not data.

requests.post(url,form_data) does send data. The sent http request is:
POST /path?query HTTP/1.1
Host: example.com
Content-Length: 146
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate, compress
Accept: */*
User-Agent: python-requests/x.x.x CPython/y.y.y Linux/z.z.z
username=amiti9124%40gmail.com&Cname=abc&Creditme=2&Fname=amitiamiti&pass=123456&numberOfFaxes=10&faxNumber1=039555555&Tkav=039111111&passC=123456
You could send the form manually in your browser and compare the requests.
The html that you see is the response from the server, after it has received your post request.

Related

Python Selenium cant interact with pop up window

first of all i wanted to say that im quite new to python and selenium in particular.
Me and a co-worker are trying to automate a web app to sort payments for us.
everything works up to the part where a pop window appears.This pop up basically its a credit card form.
The Issue is:
You can only interact with the fields, the two buttons and you can close it using the "X".
you cant inspect with developer tools, and i cant download any other programs for that because its
a work computer.
the things i found so far are the link as you can see in the address bar, and i was able to inspect it with the developer tools 'Network' tab.
here is the code that is in the window:
<html>
<head>
<title> ÷ìéèú ôøèé àùøàé </title>
</head>
<body>
<BR>
<iframe id="iFrame" width="100%" height="100%" src="" frameborder="0" ></iframe>
<script Language="JavaScript">
if (typeof(window.dialogArguments)!="undefined") document.getElementById('iFrame').src = window.dialogArguments;
</script>
</body>
</html>
the following is the code which sits inside the page itself (the input fields etc.):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<script src="merchantPages/WebSources/js/HE.js"></script>
<script src="merchantPages/leaseacar/js/main.js"></script>
<script src="merchantPages/leaseacar/js/tafnitTrack2.js"></script>
<link href="merchantPages/WebSources/css/main.rtl.css" rel="stylesheet" type="text/css" />
<title>דף תשלום מאובטח</title>
</head>
<body onload="resetForm();">
<!-- DISPLAY TRANSACTION INFORMATION -->
<div id="main_frame" align="center">
<div id="main">
<div id="page_title"><img id="ssl_logo" src="merchantPages/WebSources/images/ssl.png" alt="" title=""/><h1>דף תשלום מאובטח</h1></div>
<div id="logo"><img src="merchantPages/leaseacar/images/eTafnit.gif" alt="" title="" width="87" height="118"/></div>
<div class="sep"></div>
<div id="page_desc">
<em>עמוד זה הינו עמוד התשלום עבור העסקה שביצעת באתר.<br />תשלום בעבור ההזמנה יבוצע רק לאחר בחירה בכפתור "שליחה" שבתחתית המסך.<br />אנא אשר תחילה כי כל הפרטים בדף זה נכונים והזן את פרטי כרטיס האשראי כנדרש.</em>
</div>
<form id="creditForm" onsubmit="return formValidator(10);" method="POST" action="ProcessCreditCard">
<input type="hidden" name="txId" value="0ce8b10c-2550-4293-ac6b-fee0b61c5b80"/>
<input type="hidden" name="lang" value="HE"/>
<input type="hidden" name="last4d" value="" autocomplete="off" />
<input type="hidden" name="cavv" value="" autocomplete="off" />
<input type="hidden" name="eci" value="" autocomplete="off" />
<input type="hidden" name="transactionCode" value="Phone" autocomplete="off" />
<input type="hidden" name="expMonth" value="10" autocomplete="off" />
<input type="hidden" name="expYear" value="24" autocomplete="off" />
<input type="hidden" name="personalId" value="" autocomplete="off" />
<input type="hidden" name="userData1" value=""/>
<input type="hidden" name="userData2" value=""/>
<input type="hidden" name="userData3" value=""/>
<input type="hidden" name="userData4" value=""/>
<input type="hidden" name="userData5" value=""/>
<input type="hidden" name="userData6" value=""/>
<input type="hidden" name="userData7" value=""/>
<input type="hidden" name="userData8" value=""/>
<input type="hidden" name="userData9" value=""/>
<input type="hidden" name="userData10" value=""/>
<table class="data_tbl">
<thead>
<td colspan="4" class="td_style_1">הזנת פרטי כרטיס אשראי לתשלום</td>
</thead>
<tr>
<td class="td_style_fieldName">Card Number:</td>
<td><input type="text" id="cardNumber" name="cardNumber" maxlength="19"
style="width: 160px;" autocomplete="off" onchange="validateCardNumber();"/></td>
<td class="td_style_invalidField" id="invalidCardNumber"> </td>
</tr>
<tr>
<td class="td_style_fieldName">CVV:</td>
<td><input type="text" name="cvv" id="cvv" maxlength="4" style="width: 50px;" autocomplete="off" onchange="validateCvv();"/> <img src="merchantPages/WebSources/images/qm.png" onmouseover="showHideCVVhelp();" onmouseout="showHideCVVhelp();" style="cursor:pointer;"/><div id="CVVhelp" style="display: none; position: absolute; border: 1px #cccccc solid; padding: 10px; background: white;"><img src="merchantPages/WebSources/images/cvv.jpg" /></div></td>
<td class="td_style_invalidField" id="invalidCvv"> </td>
</tr>
<tr>
<td class="td_style_fieldName">Track2:</td>
<td><input type="password" name="track2" id="track2" value="" autocomplete="off" onchange="tafnitValidateTrack2();"/></td>
<td class="td_style_invalidField" id="invalidTrack2"> </td>
</tr>
</table>
<div id="form_buttons"><input type="submit" id="submitBtn" value="שליחה" /> | <input id="resetBtn" type="reset" value="ניקוי" /></div>
</form>
</div>
<br />
<img src="merchantPages/WebSources/images/rapidssl.gif" alt="" title=""/>
</div>
</body>
</html>
if someone could give me some advice on how could i target the window so i can close, or if its even possible.
this is what i got so far:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
#IMPORTS!-------------------------------------
usr = "***"
pwd = "***"
#app.
driver = webdriver.Ie(executable_path='C:/Users/natbag/Desktop/proj/IEDriverServer.exe')
driver.get('http://111.10.10.10/MENU1/LOGIN7.CSP')
driver.implicitly_wait(10)
username_box = driver.find_element_by_id('Username')
username_box.clear()
username_box.send_keys(usr)
password_box = driver.find_element_by_id('Password')
password_box.send_keys(pwd)
login_btn = driver.find_element_by_xpath('//input[#type="submit"]').click()
#------------------------End of Login ------------------------------------
#update contract page ----------
upd_con = driver.find_element_by_partial_link_text('עדכון חוזה').click()
#input latest Contract (F7) ----
input_con = driver.find_element_by_id('HOZ').send_keys(Keys.F7)
#goto receipts --------
receipts_btn = driver.find_element_by_xpath('//input[#name="BKBL"]').click()
Alert(driver).accept()
#input employee name ----- F7 for now later can be changed for custom number -----
work_name = driver.find_element_by_xpath('//input[#name="OVED"]').send_keys(Keys.F7)
#Receipts after username --------------------
receipts_btkn = driver.find_element_by_xpath('//input[#name="BTKBL"]').click()
#2 Seconds SLEEP IS MANDATORY!!! ----
#select Credit Card by Last Value (F7) can be changed to custom value
cc = driver.find_element_by_id('KSM').send_keys(Keys.F7)
#-------------- CANT INTERACT WITH CC WINDOW -----------------
WebDriverWait(driver, 5).until(EC.frame_to_be_available_and_switch_to_it((driver.find_element_by_xpath('//iframe[#id"iFrame"]'))))
#WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#type='text'] and [#id='cvv']"))).click()
sorry for the long post,
thanks in advance
Well i figured it out using pyautogui.
tnx everyone

signing into seedr.cc using requests

I am trying to sign into the website seedr.cc, I got names for email and pasword and I don't know the value of submit button, So I gave it Submit as the value and after post() I am checking if it is logged in but it isn't and there happens to be no error so I don't know why it isn't logging in.
import requests
r = requests.session()
res = r.get('http://seedr.cc',headers={'User-Agent':'Chrome/5.0'})
data = {
'username':username,
'password':password,
'sign-in-submit':'Submit',
}
headers = {'User-Agent':'Chrome/5.0',
}
res = r.post('http://seedr.cc',
data=data,
headers=headers,
cookies=r.cookies
)
res=r.get('https://www.seedr.cc/settings',headers=headers,cookies=r.cookies)
Thanks in Advance
Edit:
This is the form :
<form class="sign-in-form" disabled="disabled">
<div class="modal-body">
<div class="row">
<div class="large-12 columns">
<label> <span>Email</span>
<input placeholder="email" name="username" type="text" tabindex="1" required="">
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label> <a id="forgot-password-link">Forgot your password?</a> <span>Password</span>
<input placeholder="password" name="password" pattern=".{6,}" type="password" tabindex="2" title="It must contain the password that you have chosen at registration" required="">
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label style="text-align:center"> <input type="checkbox" name="rememberme" tabindex="3"> <small> Keep me logged in ( <b>this is a private computer</b> )</small> </label>
</div>
</div>
<div class="row">
<!--<div class="large-12 columns" id="login-recaptcha-container" style="text-align:center">
<div id="login-recaptcha" style="max-width: 307px;display: inline-block;"></div><br>
</div>-->
</div>
<div class="large-12 columns" id="premium-bot" style="margin-bottom: 10px;">
<small>* Premium users may skip verification -- <span data-tooltip="" aria-haspopup="true" class="has-tip" data-disable-hover="false" data-selector="tooltip-jt6znnt77" aria-describedby="tooltip-jt6znnt77" title="">why?</span></small>
</div>
</div>
<a class="close-reveal-modal">×</a>
<div class="modal-footer" style="margin: 0 13px 0 13px;border-top: none;">
<button style="margin-bottom:0;background: rgb(80, 139, 208);WIDTH: 100%;border-radius: 5px;" name="sign-in-submit" type="submit" class="button radius" tabindex="5"><i class="fa fa-check"></i> Login</button>
<div id="login-separator">
- OR - </div>
<button type="button" onclick="javascript:FBlogin(false,$(this).closest('form').find('input[name=rememberme]').prop('checked'));return false;" style="margin-bottom:0;background: #354E84;WIDTH: 100%;border-radius: 5px;line-height: 100%;" name="sign-in-submit" class="button radius"><img src="https://static.seedr.cc/images/facebook_icon.png" style="
line-height: 35px;
margin-right: 8px;
vertical-align: -5px;
"> Login with Facebook </button>
<small class="facebook-email-required" style="
text-align: left;
width: 100%;
color: red;
padding: 10px;
display:none;
">Email access is required for login , please try again</small>
</div>
</form>

AttributeError: 'module' object has no attribute 'document'

I am trying to enter username and password using python(2.7.10) and selenium and running into below error?how to fix it?
CODE:-
from selenium import webdriver
import selenium
driver = webdriver.Chrome("/Users/username/Downloads/chromedriver")
driver.get("http://website.com")
username = selenium.document.getElementById("Username")
password = selenium.document.getElementById("Password")
username.send_keys("username")
password.send_keys("password")
selenium.find_element_by_name("Login").click()
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>company Central Login</title>
<link rel="stylesheet" type="text/css" href="/themes/bootstrap/theme.css" />
<link rel="icon" type="image/png" href="/themes/bootstrap/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<style type="text/css">
.vertical-align {
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
flex-direction: column;
}
.vertical-align > [class^="col-"],
.vertical-align > [class*=" col-"] {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
min-height: 24em;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
</style>
</head>
<body onload="if (document.getElementById('username')) document.getElementById('username').focus()">
<div class="container">
<div class="row vertical-align">
<div class="col-md-6 col-md-offset-3">
<form class="form" method="post" id="login-form" action="login"
onsubmit="submitbutton = document.getElementById('login-submit'); submitbutton.value='Please wait...'; submitbutton.disabled=true; return true;">
<h2 style="text-align: center;">Open Directory Login</h2>
<div class="row">
<div class="form-group col-md-6">
<label for="username">Username</label>
<input class="form-control" placeholder="Open Directory Username" id="username" name="username" size="30" type="text" tabindex="1" accesskey="u" />
</div>
<div class="form-group col-md-6">
<label for="password">Password</label>
<input class="form-control" placeholder="Open Directory Password" id="password" name="password" size="30" type="password" tabindex="2" accesskey="p" autocomplete="off" />
</div>
</div>
<div style="text-align: right">
<input type="submit" class="btn btn-success" accesskey="l" value="Login" tabindex="4" id="login-submit">
</div>
<input type="hidden" id="lt" name="lt" value="LT-1521352536r2EFE1A5DD6D459C1E4" />
<input type="hidden" id="service" name="service" value="http://wifi-tech-web.company.com:8080/login" />
<input type="hidden" id="from" name="from" value="" />
</form>
</div>
</div>
</div>
</body>
</html>
Error:-
AttributeError: 'module' object has no attribute 'document'
Selenium is a module, and it doesn't have a document attribute, you need to use the webdriver to locate the element. document.getElementById is not a Python syntax anyway, its JavaScript. Try
username = driver.find_element_by_id('username')
Keep in mind that the search is case sensitive, username is all in lowercase letters.

How do I Login to A site using Python for scraping purposes

I'm relatively new to python and programming generally. I've tried to follow steps provided from similar questions here but My program is unable to successfully Log in. The latest code I got from How to scrape a website which requires login using python and beautifulsoup?
Below is my attempted code: and the response I get
import mechanize
import BeautifulSoup
import urllib2
import cookielib
cj = cookielib.CookieJar()
br = mechanize.Browser()
br.set_cookiejar(cj)
br.open("http://www.bbnplace.com/accounts_v2/?do=signin&service=prepaidsms&returnto=http%3A%2F%2Fsms.bbnplace.com%2Fsentdir.php")
br.select_form('blogin')
br.form['busername'] = 'my_username'
br.form['passwd'] = 'my_password'
response = br.submit()
print br.response().read()
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="keywords" content="bulksms, bulk sms, bulk sms gateway, cheap bulk sms, bulk sms provider, bulk sms to nigeria, send bulk sms, personalized bulk sms, bulk sms nigeria, best sms site in nigeria, nigerian bulks sms gateway, web to mobile sms" />
<meta http-equiv="description" content="Send bulk sms with personalized sender name to all GSM networks in Nigeria and over 800 networks in 160 countries. Nigeria's Best SMS Gateway." />
<title>BBN SMS Messenger: Retail Web to Mobile Bulk SMS Messaging Utility</title>
<link rel="stylesheet" href="http://www.bbnplace.com/accounts_v2/style/layout.css" type="text/css" media="screen" />
<script type="text/javascript" async src="http://www.bbnplace.com/accounts_v2/bbjs/un.js"></script>
<script type="text/javascript">var L;var C;var bw=0;var G;var eD;var am;var eE=0;var method;var url;var J;var be;var fp='';var eY='';var dW=0;var eH='dG';var eG;var action='sent';var bS=0;var eC='';var eW=new Number();var bP='';var ft='save';var host=document.domain=='localhost'?'localhost/smsmessenger/':'sms.bbnplace.com';var protocol='http';var fc;var eA=protocol+"://"+host+"/source/";var dR=0;var responseText;var response=new Array();var bs;var bV=new Number();var H;var request;var fl;var aB;var aQ;var aL=window.innerWidth;var ab=window.innerHeight;var ca=new Array();var aK=new Array();var cv=new Array();var bb=new Array();var dN=new Array();aB=document.getElementById('aD');var et=110;aQ=document.getElementById('bx');if(request=='gocheck'){ad();}function ak(v){var k=document.getElementById(v);k.style.visibility='hidden';k.style.height='0px';};function aE(v){var k=document.getElementById(v);k.style.visibility='inherit';k.style.height='auto';};function bJ(v,ba){var ids=new Array();var aw=new String();aw=ba;ids=aw.split(',');for(var i=0;i<ids.length;i++){ak(ids[i]);}ids='';aE(v);return;};function ay(bF,cF,dw,bH,bi,aq,bN,aA){be=bi;C=bH;G=aq;H=aA;J=dw;method=bF;url=cF;am=bN;L=bO();if(L){if(method=='post'){try{L.open(method,url,true);L.onreadystatechange=bg;L.setRequestHeader('Content-Type','application/x-www-form-urlencoded');L.setRequestHeader('Content-Length',J.length);L.setRequestHeader('Connection','close');L.send(J);}catch(e){alert("Error connecting to server: "+e.toString());}}else{try{J.length>1?aG=url+'?'+J:aG=url;L.open(method,aG,true);L.onreadystatechange=bg;L.send(null);}catch(e){alert("Could not connect to server: "+e.toString());}}}};function bg(){var d;if(C.length>0){d=document.getElementById(C);}if(L.readyState==4){if(L.status==200){try{var response=dO();if(C.length>0){d.style.visibility='hidden';}bw=0;}catch(e){d.innerHTML="Error reading server response: "+e.toString();}}else{if(C.length>0){if(L.status){d.innerHTML='Server Response: '+L.status+' - '+L.statusText;d.style.visibility='visible';}else{d.innerHTML='Connection to server failed. Retrying...';d.style.visibility='visible';bQ=setTimeout('bz()',5000);}}}}else{if(C.length>0){d.innerHTML='<img border="0" src="style/29.gif" align="absmiddle" /> <b>Loading...</b>';d.style.visibility='visible';ap=setTimeout('dK()',(be*1000));}}return response;};function dK(){if(L.readyState!=4){clearTimeout(ap);document.getElementById(C).innerHTML='Connection is too slow. Retrying...';bQ=setTimeout('bD()',5000);}};function bD(){clearTimeout(bQ);if(L.readyState!=4){L.abort();ay(method,url,J,C,be,G,H);}};function bz(){clearTimeout(bQ);if(!L.status){L.abort();ay(method,url,J,C,be,G,H);}};function df(){x=document.getElementById(C);x.style.visibility='hidden';};function dO(){var responseText,cp;var doctype=L.getResponseHeader('Content-Type').toString();var l=document.getElementById(G);if(H.length){var aJ=document.getElementById(H);}l.innerHTML='';response['type']=doctype;if(doctype=='text/plain'||doctype=='text/html'){responseText=L.responseText;if(responseText.substr(0,4)=='Err:'){l.innerHTML=responseText.substr(5);l.style.visibility='inherit';l.style.height='auto';if(responseText.substr(5)==''){if(bS>0){l.innerHTML='<span style="color:red;">'+bP+'</span>';}}}else if(responseText.substr(0,3)=='OK:'){var aH=responseText.substr(4);switch(request){case 'newpost':document.forms[request].es.value=aH;bs.innerHTML='Saved';eu();break;}}else{if(H.length){aJ.innerHTML=responseText;}else if(request=='gocheck'){l.innerHTML=responseText;y=document.forms.di;if(responseText=='available'){y.cf.value=1;y.ds.value=y.username.value;l.innerHTML='Available';l.style.fontWeight='bold';l.style.color='green';ad();}}else{if(responseText=='successful'){switch(request){case 'newRequest':bJ('h','h,j');break;}}else if(responseText=='denied'){bf=protocol+'://'+host+'/accounts';window.location=bf;}else{alert(responseText);}}}}};function bO(){try{L=new XMLHttpRequest();}catch(e){var aI=new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP');for(var i=0;i<aI.length&& !L;i++){try{L=new ActiveXObject(aI[i]);}catch(e){}}}if(!L){alert('Please Upgrade your web browser');}else{return L;}};function aN(){var x=document.forms['t'];request='newRequest';aq='V';var bp,ao,aW,az;bp=x.ag.value;ao=x.bI.value;aW=x.aR.value;dr=x.an.value;az=x.av.value;aZ='eml='+encodeURIComponent(ao)+'&f='+encodeURIComponent(bp)+'&p='+encodeURIComponent(aW)+'&m='+encodeURIComponent(az)+'&p2='+encodeURIComponent(dr);al=document.getElementById('V');al.style.visibility='hidden';al.style.height=0;dP='source/contact.php';ay('post',dP,aZ,'',30,'V','','');};function cu(){dJ();};function cl(){ce();};function bB(aX){var x=document.getElementById('bh');if(!x){var x=document.createElement('div');x.setAttribute('id','bh');x.style.backgroundColor='#000';x.style.top='0px';x.style.left='0px';x.style.position='fixed';x.style.zIndex=99999;x.style.opacity=0.5;}x.style.width=aL+'px';x.style.height=ab+'px';x.style.visibility='visible';document.body.appendChild(x);if(aX==null){var T=document.getElementById('t');T.style.visibility='visible';T.style.height='auto';T.style.position='fixed';T.style.left=(aL/2-250)+'px';T.style.width='500px';T.style.zIndex=10000001;bJ('j','h,j');}else{var T=document.getElementById('ax');T.style.visibility='visible';bV=aX;}};function ar(){var bE=document.getElementById('bh');bE.style.width='0px';bE.style.height='0px';bE.style.visibility='hidden';if(bV==0){ak('h');ak('j');ak('t');document.forms['t'].reset();}else{var T=document.getElementById('ax');T.style.visibility='hidden';bV=0;}};function cU(i){var aY=document.getElementById('bA');aY.innerHTML='<b>Message:</b><br />'+aK[i];aY.innerHTML+='<br /><br /><b>Broadcasted:</b> '+bb[i];document.getElementById('as').style.visibility='visible';ez(ca[i]);};function dA(){document.getElementById('as').style.visibility='hidden';document.getElementById('ae').innerHTML='';}</script>
</head>
<body><div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=174240488183";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script><div id="ppbd"></div><div id="ppbdc"></div><div id="logoholder"></div>
<div id="app_header">
<div id="line1_left"><img src="http://www.bbnplace.com/accounts_v2/style/smlogo.png" align="absmiddle" title="BBN SMS Messenger: Retail Web to Mobile Bulk SMS Messaging Utility" /></div>
<div id="line1_right">Hi Buddie! | Messaging Solutions | BBN </div>
</div>
<div id="cK" align="right"> </div><div id="workarea" align="center">
<div id="frm_right">
<div id="note_panel"><div align="left">
<!-- <div style="margin: 0 0 40px; font-size: 22px; line-height: 27px;">
manage your contacts • send sms to <b style="color: red;">groups</b>
• from personal computer and <b style="color: red;">mobile</b>
</div> -->
<div style="font-size: 28px; line-height: 35px; margin: 35px 0 0;">
Send bulk sms • <b style="color: red;">confidently!</b>
</div>
<div id="bslogin_nav">
<img alt="How to Recharge" src="style/cc_icon.png" align="absmiddle" />
<b>Learn How to Recharge</b> <img
alt="Bundles and Pricing" align="absmiddle" src="style/cog_icon.png" />
<b><a
href="http://www.bbnplace.com/documentation/?service=prepaidsms&article=networks&returnto="
target="_blank">See our Network Coverage</a></b>
</div>
<script type="text/javascript">function dJ(){var x=document.forms['aN'];var V=new Number(x.df.value);var v=new Number(0);if(isNaN(V)){document.getElementById("J").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("hBp").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("T").innerHTML="<span style='color: red;'>waiting...</span>";if(document.forms.F){document.forms.F.bJ.disabled=true;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML="<span style='color: red;'><strong>Please Enter a Numberic Value</strong></span>";}}if(V<50){document.getElementById("J").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("hBp").innerHTML="<span style='color: red;'>waiting...</span>";document.getElementById("T").innerHTML="<span style='color: red;'>waiting...</span>";if(document.forms.F){document.forms.F.bJ.disabled=true;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML="<span style='color: red;'><strong>Please specify a minimum of 50</strong></span>";}}else if(V>=50&&V< 1000){document.getElementById("J").innerHTML="Teams & Groups";document.getElementById("hBp").innerHTML="NGN 3.50";v=V* 3.50;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Teams & Groups';document.forms.F.hBp.value= 3.50;document.forms.F.T.value=v;}}else if(V>= 1000 &&V< 10000){document.getElementById("J").innerHTML="Business Standard";document.getElementById("hBp").innerHTML="NGN 2.20";v=V* 2.20;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Business Standard';document.forms.F.hBp.value= 2.20;document.forms.F.T.value=v;}}else if(V>= 10000 &&V< 50000){document.getElementById("J").innerHTML="Business Professional";document.getElementById("hBp").innerHTML="NGN 2.00";v=V* 2.00;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Business Professional';document.forms.F.hBp.value= 2.00;document.forms.F.T.value=v;}}else if(V>= 50000){document.getElementById("J").innerHTML="Business Premium";document.getElementById("hBp").innerHTML="NGN 1.85";v=V* 1.85;v=v.toFixed(2);document.getElementById("T").innerHTML='NGN '+v;if(document.forms.F){document.forms.F.bJ.disabled=false;}if(document.getElementById("statMsg")){document.getElementById("statMsg").innerHTML='';}if(document.forms.F){document.forms.F.J.value='Business Premium';document.forms.F.hBp.value= 1.85;document.forms.F.T.value=v;}}} </script>
<div align="left" id="pricelist">
<div align="right"><div id="price_tag"><img src="http://www.bbnplace.com/accounts_v2/style/price_tag.png" align="top" /> Bundles & Pricing</div></div>
<form id="aN" name="aN" method="post" action="">
<div style="margin: 0 0 5px;">
<label for="select"></label> <b>Currency</b> <select
name="aD" id="aD" onchange="ck(this.value)" disabled="disabled">
<option value="ngn" selected="selected" >NGN</option>
<option value="usd" >USD</option>
<option value="eur" >EUR</option>
</select>
</div>
<div>
<table cellpadding="3" cellspacing="0" width="100%" id="price_tags">
<tr>
<th align="left">Bundle</th>
<th width="120" align="right">Min. Volume</th>
<th width="80" align="right">Unit Price</th>
</tr> <tr>
<td style="background-color: #FFF; white-space:nowrap; overflow:hidden; text-overflow: clip;">Teams & Groups</td>
<td align="right" style="background-color: #FFF;">50</td>
<td align="right" style="background-color: #FFF;">3.50</td>
</tr> <tr>
<td style="background-color: #FAFAFA; white-space:nowrap; overflow:hidden; text-overflow: clip;">Business Standard</td>
<td align="right" style="background-color: #FAFAFA;">1,000</td>
<td align="right" style="background-color: #FAFAFA;">2.20</td>
</tr> <tr>
<td style="background-color: #FFF; white-space:nowrap; overflow:hidden; text-overflow: clip;">Business Professional</td>
<td align="right" style="background-color: #FFF;">10,000</td>
<td align="right" style="background-color: #FFF;">2.00</td>
</tr> <tr>
<td style="background-color: #FAFAFA; white-space:nowrap; overflow:hidden; text-overflow: clip;">Business Premium</td>
<td align="right" style="background-color: #FAFAFA;">50,000</td>
<td align="right" style="background-color: #FAFAFA;">1.85</td>
</tr> </table>
</div>
<div style="margin: 30px 0;">
Specify sms volume in the space below to get pricing <br />
<div>
<table width="100%" border="0" cellpadding="2" cellspacing="0"
id="aH">
<tr>
<th width="80">Volume</th>
<th width="">Bundle</th>
<th width="80" align="right">Unit Price</th>
<th width="" align="right">Price</th>
</tr>
<tr>
<td bgcolor="#FEFEFE"><input name="df" type="text" value=""
size="10" maxlength="10" onkeyup="dJ()" /></td>
<td bgcolor="#FEFEFE"><div id="J">
<input name="J" type="hidden" id="J" value="" />
</div></td>
<td align="right"><div id="hBp">
<input name="hBp" type="hidden" id="hBp" value="" />
</div></td>
<td align="right"><div id="T"><a name="how_to_recharge"></a>
<input name="T" type="hidden" id="T" value="" />
</div></td>
</tr>
</table>
</div>
</div>
</form>
IMPORTANT: *<strong>Business Premium bundle</strong> is the only <span
style="color: red; font-weight: bold;">negotiable</span> bundle.
</div><div align="left" style="margin: 50px 0 0;">
<h2>How to Recharge</h2>
<p>Pay online with any Nigerian debit/credit card, or at any branch of the listed banks:</p>
<div>
<img alt="web payment" src="http://www.bbnplace.com/checkout/image/webpaymentgateways.gif" height="55" />
</div>
<div style="font-size: 14px;">
Account Name: <b>Browser Based Nigeria</b>
</div>
<div style="clear: both; width: 100%;">
<div id="bM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/zenith.jpeg"
alt="Zenith Bank" width="50" height="50" /><br />1012259075
</div>
<div id="bM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/gtblogo.gif"
alt="Guaranty Trust Bank" width="50" height="50" /><br />0008382123
</div>
<div id="bM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/diamondbank.jpg"
alt="Diamond Bank Plc" width="50" height="50" /><br />0010549507
</div>
<div id="ibM" align="center">
<img src="http://www.bbnplace.com/sms/media/images/accessbank_logo.png"
alt="Access Bank Plc" height="30" style="padding: 5px 0;" /><br />0049632011</div>
</div>
</div></div></div>
<div id="form_pane">
<div id="form_panel"><div align="left" id="signup">
<form name="signup_init" method="post" onsubmit = "return false;" autocomplete="off">
<div align="right"><h2>Get Started!</h2></div>
<div id="signup_init_error_message"></div>
<div><b>Email</b></div>
<div>
<input name="new_user_email" type="email" id="new_user_email" onkeypress="quickSubmit(event, 'signup_init', 'signup_init_error_message')" title="Type Email" size="45" style="width:100%" />
<span style="display: none;">User Email</span>
</div>
<div>
<input type="hidden" name="validemail" value="0" />
<input type="hidden" name="bservice" value="prepaidsms" />
<input type="button" name="button2" id="aC" value="Sign Up" onclick="processFrm('signup_init', 'signup_init_error_message');" />
</div>
</form>
</div></div>
<div id="forms_seperator">OR</div>
<div id="form_panel"><div>
<form name="blogin" method="post" onsubmit="return false;" autocomplete="off">
<div align="right"> <h2>Login</h2> </div>
<div id="errormsg"></div>
<div align="left">Email<br />
<label for="username"></label>
<input type="email" name="busername" id="busername" class="frmfield" value="" onkeypress="quickSubmit(event, 'blogin', 'errormsg')" title="This should be your email" />
</div>
<div align="left">Password<br />
<input type="password" name="passwd" id="passwd" class="frmfield" value="" onkeypress="quickSubmit(event, 'blogin', 'errormsg')" />
</div>
<div>
<input type="hidden" name="bservice" id="bservice" value="prepaidsms" />
<input type="hidden" name="returnto" id="returnto" value="http://sms.bbnplace.com/sentdir.php" />
<input type="hidden" name="errordiv" id="errordiv" value="errormsg" />
<input type="hidden" name="ipaddress" id="ipaddress" value="41.58.242.131" />
</div>
<div align="left">
<label><input name="rememberme" type="checkbox" id="rememberme" value="1" /> Remember Me!</label>
<input type="button" name="button" id="button" class="K" value="Login" onclick="processFrm('blogin','errormsg')" />
</div>
<div style="padding: 5px 0;">Can't access my account</div>
</form>
</div></div>
<div style="margin: 18px 0;">
<div style="margin: 0 0 5px;">Join our social conversation</div>
<div class="fb-like" data-href="http://www.facebook.com/bbnsms"
data-send="false" data-layout="button_count" data-width="250"
data-show-faces="false"></div>
</div>
</div>
</div></div>
<div style="clear:both;"> </div><div id="statsbar"></div>
</div>
<div id="aj" align="center"></div>
<div align="center" id="bn">
<a href="//bs.bbnplace.com" title="Business Solutions">Business
Solutions</a> | Developers | Documentation
| Newsroom
| Blog | <a
href="//www.bbnplace.com?entry=contact" target="_blank">Contact
Us</a> <a href="//twitter.com/bbnplace" title="on Twitter"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/twitter.png" alt="on Twitter"
width="16" height="16" border="0" /></a> <a
href="//www.facebook.com/bbnplace" title="on Facebook"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/facebook.png" alt="on Facebook"
width="16" height="16" border="0" /></a> <a
href="//www.linkedin.com/groups?gid=4620527" title="at LinkedIn"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/linkedin.png" alt="at LinkedIn"
width="16" height="16" border="0" /></a> <a
href="//www.youtube.com/user/bbnplace" title="on Youtube"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/youtube.png" alt="on Youtube"
width="16" height="16" border="0" /></a> <a
href="//newsroom.bbnplace.com" title="at the Newsroom"
target="_blank"><img src="//www.bbnplace.com/accounts_v2/style/radio.png" alt="Newsroom" width="16"
height="16" border="0" /></a>
<br /> Copyright © 2008 - 2016 <a
href="//www.bbnplace.com" title="Browser Based Network Ltd">Browser
Based Network Ltd</a>. <img src="//www.bbnplace.com/accounts_v2/style/ngr.png" align="absmiddle"
alt="Nigeria" /> Nigeria. All rights reserved.
<br />Terms of Service • Privacy Policy Statement
<br /> <b>Desktop | Mobile Edition
</b>
</div>
<div
style="float: right; position: fixed; z-index: 100000; top: 230px; right: 0px;">
<img src="//www.bbnplace.com/accounts_v2/style/feedback_button.png" onclick="bB()"
style="cursor: pointer;" />
</div><div id="t">
<div id="j">
<form name="t" action="return false;" method="post">
<input type="hidden" name="an" value="Mobile Messaging Solutions" />
<h1 style="color: #555;">Send Us Feedback</h1>
<div>If you notice something is not working properly or you have a
suggestions. We appreciate hearing from you</div>
<div id="V"></div>
<div>
<b>Full Name:</b><br /> <input type="text" name="ag"
style="width: 95%;" />
</div>
<div>
<b>Email:</b><br /> <input type="text" name="bI" style="width: 95%;" />
</div>
<div>
<b>Phone:</b> <i>(optional)</i><br /> <input type="text" name="aR"
style="width: 200px;" />
</div>
<div>
<b>Suggestion:</b><br />
<textarea name="av" rows="10"
style="width: 95%; min-width: 95%; max-width: 95%; height: 100px; max-height: 100px;"></textarea>
</div>
<div>
Read our <a href="http://docs.bbnplace.com/?article=privacy_policy"
target="_blank">Privacy Policy</a> statement
</div>
<div style="margin: 10px 0 0;">
<span id="aC" onclick="aN()">Submit Feedback</span> <span class="K"
onclick="ar()">Cancel</span>
</div>
</form>
</div>
<div id="h">
<div id="bv">
<img src="style/correct_marking.gif" align="absmiddle" /> Your
feedback has been received. Thank you for the time taken
</div>
<div style="margin: 50px 0 0;">
<span class="K" onclick="ar()">Close</span>
</div>
</div>
</div><div id="cs"><div style="text-align:center;white-space:nowrap;"> <div><img alt="Live chat" src="https://cbi.boldchat.com/aid/4518259610467392165/bc.cbi?cbdid=6794783422064795815" border="0"/></div></div></div></body>
</html>
You just need to post to the correct url, once successfully logged in you will be able to get whatever page you like, this is a working example using requests:
import requests
from bs4 import BeautifulSoup
post = "http://www.bbnplace.com/accounts_v2/source/loginp.php"
data = {"eml": "your_email",
"p": "your_pass"}
# use a Session to persist cookies.
with requests.Session() as s:
r = s.post(post, data=data) # log us in
print(r.content) # will output "successful" for correct login
r = s.get("http://sms.bbnplace.com/account.php") # get account page
soup = BeautifulSoup(r.content)
print(soup.title.text)

How to select from drop down box using selenium webdriver

I am trying to select Channel in a webpage from Drop Down Box using selenimum webdriver (Python). HTML is given below:
<iframe id="page" frameborder="0" src="DashBoard.htm" onfocus="this.blur()" scrolling="no" cellspacing="0" border="0" name="page" style="width: 1076px; height: 525px; margin-left: 30px; margin-top: 0px; visibility: visible;">
<!DOCTYPE html>
<html>
<head>
<body class="page-body" onresize="change_size();" onload="change_size();initScrn();setKeys();showWpsAlert();highLightMenu('setup_header', 'wireless_set');">
<img class="cover-image" src="img/cover-image_noh.gif" style="display: none;">
<img class="body-image" src="img/subhead2-background_noh.jpg" style="width: 1076px; height: 495px; position: absolute; top: 5px;">
<div id="full-page-container">
<form id="target" action="wireless.cgi?id=1484693214" method="POST">
<input type="hidden" name="buttonHit">
<input type="hidden" name="buttonValue">
<img class="subtop-image" src="img/subhead2-top_noh.gif" style="width: 1076px; height: 32px;">
<div class="subhead2"> Wireless Setup</div>
<table class="subhead2-table" border="0" style="height: 405px; position: relative; top: -3px; width: 1049px;">
<tbody>
<tr valign="middle" align="left">
<tr>
<td class="scrollpane-table-seperate-border" colspan="2">
<div class="scroll-pane" style="height: 405px; width: 1049px; overflow: auto;">
<table style="border-collapse:collapse;width:97%">
<tbody>
<tr>
<tr>
<tr>
<tr>
<td colspan="2">
<div id="setting_2G" style="display: block;">
<table cellspacing="0" cellpadding="0" border="0" width="100%" <table="">
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<td nowrap="">Channel:</td>
<td nowrap="">
<select size="1" name="w_channel">
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr valign="middle" align="center">
</tbody>
</table>
<img class="subfooter-image" src="img/subhead2-bottom.gif" style="width: 1076px; height: 24px; position: relative; top: -3px;">
<div class="subhead2-bottom" style="width: 1076px;">
<input type="hidden" value="0" name="tempSetting">
<input type="hidden" value="5" name="tempRegion">
<input type="hidden" value="17" name="setRegion">
<input type="hidden" value="0" name="wds_enable">
<input type="hidden" value="0" name="wds_enable_an">
<input type="hidden" value="0" name="only_mode">
<input type="hidden" value="0" name="show_wps_alert">
<input type="hidden" value="WPA-AUTO-PSK" name="security_type_2G">
<input type="hidden" value="WPA-AUTO-PSK" name="security_type_5G">
<input type="hidden" value="WPA-AUTO-PSK" name="init_security_type_2G">
<input type="hidden" value="WPA-AUTO-PSK" name="init_security_type_5G">
<input type="hidden" value="11" name="initChannel">
<input type="hidden" value="automatic" name="initAuthType">
<input type="hidden" value="0" name="initDefaultKey">
<input type="hidden" value="161" name="initChannel_an">
<input type="hidden" value="automatic" name="initAuthType_an">
<input type="hidden" value="0" name="initDefaultKey_an">
<input type="hidden" value="1" name="telec_dfs_ch_enable">
<input type="hidden" value="0" name="ce_dfs_ch_enable">
<input type="hidden" value="0" name="fcc_dfs_ch_enable">
<input type="hidden" value="1" name="auto_channel_5G">
<input type="hidden" value="1" name="support_ac_mode">
<input type="hidden" value="U12H270T00_NETGEAR" name="board_id">
<input type="hidden" value="0" name="enable_band_steering">
<input type="hidden" value="SKU_WW" name="fw_sku">
<input type="hidden" value="0.0.0.0" name="wla_radius_ipaddr">
<input type="hidden" value="0.0.0.0" name="wlg_radius_ipaddr">
<input type="hidden" value="WPA-AUTO" name="wla_ent_secu_type">
<input type="hidden" value="WPA-AUTO" name="wlg_ent_secu_type">
<input type="hidden" value="192.168.0.100" name="wan_ipaddr">
<input type="hidden" value="255.255.255.0" name="wan_netmask">
<a name="helpframe-anchor"></a>
</form>
</div>
<meta content="R7000" name="description">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="text/css" http-equiv="Content-Style-Type">
<meta content="no-cache" http-equiv="Pragma">
<meta content="no-cache" http-equiv="Cache-Control">
<meta content="Mon, 06 Jan 1990 00:00:01 GMT" http-equiv="Expires">
</body>
</html>
</iframe>
I have following python code:
driver.find_element_by_css_selector("#WLS_menu > span").click()
Select(driver.find_element_by_name("w_channel")).select_by_visible_text("12")
driver.find_element_by_name("Apply").click()
I am getting following error:
File "netgear", line 23, in test_netge Select(driver.find_element_by_name("w_channel")).select_by_visible_text("12")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: {"method":"name","selector":"w_channel"}
Am I missing something in my code?
yes please try with xpath
driver.find_element_by_xpath("//*[#id='setting_2G']/table/tbody/tr[5]/td[2]/select").send_keys("12")
UPDATE
so in that case you have to switch to frame then (Please note i am a java guy so below answer is in java for python update it into python)
WebDriver driver = new FirefoxDriver();
driver.get("‪C:\\Users\\rajnish\\Desktop\\mytest.html");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.switchTo().frame("page");
driver.findElement(By.xpath("//*[#id='setting_2G']/table/tbody/tr[5]/td[2]/select")).sendKeys("12");

Categories