Fillout form in IE using VBA - excel

Looking to fill out a form in IE from a specific cell on my sheet; research has brought me to:
Function FillInternetForm()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://helppointinfo.farmersinsurance.com/OCR/Labor_Rates/laborrates.asp"
'go to web page listed inside quotes
ie.Visible = True
While ie.Busy
DoEvents 'wait until IE is done loading page.
Wend
ie.Document.all("RatesForm").Value = Sheets("NAT").Range("C2").Value
End Function
UPDATED
<html>
<head>
<meta name="GENERATOR" content="Microsoft Visual Studio 6.0" />
<title>Labor Rates</title>
<script language="javascript" type="text/javascript">
//Function is called when Enter Zip text box is changed or when Drill down zip is selected
function FindRates() {
if (document.RatesForm.DirectZip.value + "Empty" != "Empty" && document.RatesForm.ZipDD.value + "Empty" != "Empty") {
if (ValidateZip()) {
document.RatesForm.StateDD.value = ""
var strZipCode = document.RatesForm.ZipDD.value
document.getElementById("ErrorZip").style.display = "None"
document.getElementsByTagName("IFRAME").item("DisplayReport").src = "RatesHandler.asp?ZipCode=" + strZipCode
}
else {
document.getElementById("ErrorZip").style.display = "Block"
}
}
else if (document.RatesForm.DirectZip.value + "Empty" != "Empty") {
if (ValidateZip()) {
document.RatesForm.StateDD.value = ""
var strZipCode = document.RatesForm.DirectZip.value
document.getElementById("ErrorZip").style.display = "None"
document.RatesForm.submit();
document.getElementsByTagName("IFRAME").item("DisplayReport").src = "RatesHandler.asp?ZipCode=" + strZipCode
}
else {
document.getElementById("ErrorZip").style.display = "Block"
}
}
}
//Function called when State is selected from state Drop Down
function StateRates() {
var strState = document.RatesForm.StateDD.value
document.getElementsByTagName("IFRAME").item("DisplayReport").src = "RatesHandler.asp?State=" + strState
document.RatesForm.DirectZip.value = ""
document.RatesForm.ZipDD.value = ""
document.getElementById("ErrorZip").style.display = "None"
document.getElementById("TabTag").style.display = "None"
}
//Function Disables the Drill Down Zip to stop a double function issue
function disableDD() {
document.RatesForm.ZipDD.disabled = true;
document.getElementById("TabTag").style.display = "Block"
}
function ValidateZip() {
var re = /^\d{5}([\-]\d{4})?$/;
var testBool = re.test(document.RatesForm.DirectZip.value);
return (testBool);
}
function disableEnterKey(e) {
var key;
if (window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13)
return false;
else
return true;
}
</script>
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>
<body>
<div class="DocumentTitle">Labor Rates Lookup</div>
<form name="RatesForm" method="post" >
<table class="SearchTable" border="0" cellpadding="0" cellspacing="0">
<tr class="SearchHeader">
<td colspan="2" >By Zip</td>
</tr>
<tr class="SearchRow">
<td>Enter Zip <br /><input class="SearchInput" id="DirectZip" name="DirectZip" value="" onkeypress="return disableEnterKey(event)" onblur="FindRates();" onfocus="disableDD();" /></td>
<td>
<span style="display:block;">Drill Down Zip<br />
<select disabled = "disabled" id="Select1" name="ZipDD" class="SearchSelect" style="width:200px;"onchange="FindRates();">
<option class='SearchSelect' selected='selected'>Please Enter Zip</option>
<option class='SearchSelect' selected='selected'></option>
</select>
</span>
</td>
</tr>
<tr class="SearchRow" style="text-align:center"><td colspan="2"><span id="ErrorZip" style="display:none;color:Red;">Please Enter a Valid US Zip Code!</span></td></tr>
<tr class="SearchRow" style="text-align:center"><td colspan="2"><span id="TabTag" style="display:none">Enter Zip Code and hit Tab.</span></td></tr>
<tr class="SearchHeader">
<td colspan="2" >By State</td>
</tr>
<tr class="SearchRow">
<td colspan="2" style="text-align:center;" >
<select id="ByState" name="StateDD" class="SearchSelect" onchange="StateRates();">
<option selected="selected"></option>
<option value = "AL" style='width:98%'>Alabama</option>
<option value = "AK" style='width:98%'>Alaska</option>
<option value = "AZ" style='width:98%'>Arizona</option>
<option value = "AR" style='width:98%'>Arkansas</option>
<option value = "CA" style='width:98%'>California</option>
<option value = "CO" style='width:98%'>Colorado</option>
<option value = "CT" style='width:98%'>Connecticut</option>
<option value = "DE" style='width:98%'>Delaware</option>
<option value = "DC" style='width:98%'>Dist. Columbia</option>
<option value = "FL" style='width:98%'>Florida</option>
<option value = "GA" style='width:98%'>Georgia</option>
<option value = "HI" style='width:98%'>Hawaii</option>
<option value = "ID" style='width:98%'>Idaho</option>
<option value = "IL" style='width:98%'>Illinois</option>
<option value = "IN" style='width:98%'>Indiana</option>
<option value = "IA" style='width:98%'>Iowa</option>
<option value = "KS" style='width:98%'>Kansas</option>
<option value = "KY" style='width:98%'>Kentucky</option>
<option value = "LA" style='width:98%'>Louisiana</option>
<option value = "ME" style='width:98%'>Maine</option>
<option value = "MD" style='width:98%'>Maryland</option>
<option value = "MA" style='width:98%'>Massachusetts</option>
<option value = "MI" style='width:98%'>Michigan</option>
<option value = "MN" style='width:98%'>Minnesota</option>
<option value = "MS" style='width:98%'>Mississippi</option>
<option value = "MO" style='width:98%'>Missouri</option>
<option value = "MT" style='width:98%'>Montana</option>
<option value = "NE" style='width:98%'>Nebraska</option>
<option value = "NV" style='width:98%'>Nevada</option>
<option value = "NH" style='width:98%'>New Hampshire</option>
<option value = "NJ" style='width:98%'>New Jersey</option>
<option value = "NM" style='width:98%'>New Mexico</option>
<option value = "NY" style='width:98%'>New York</option>
<option value = "NC" style='width:98%'>North Carolina</option>
<option value = "ND" style='width:98%'>North Dakota</option>
<option value = "OH" style='width:98%'>Ohio</option>
<option value = "OK" style='width:98%'>Oklahoma</option>
<option value = "OR" style='width:98%'>Oregon</option>
<option value = "PA" style='width:98%'>Pennsylvania</option>
<option value = "RI" style='width:98%'>Rhode Island</option>
<option value = "SC" style='width:98%'>South Carolina</option>
<option value = "SD" style='width:98%'>South Dakota</option>
<option value = "TN" style='width:98%'>Tennessee</option>
<option value = "TX" style='width:98%'>Texas</option>
<option value = "UN" style='width:98%'>Unknown</option>
<option value = "UT" style='width:98%'>Utah</option>
<option value = "VT" style='width:98%'>Vermont</option>
<option value = "VA" style='width:98%'>Virginia</option>
<option value = "WA" style='width:98%'>Washington</option>
<option value = "WV" style='width:98%'>West Virginia</option>
<option value = "WI" style='width:98%'>Wisconsin</option>
<option value = "WY" style='width:98%'>Wyoming</option>
</select>
</td>
</tr>
</table>
</form>
<div>
<iframe name="DisplayReport" id="DisplayReport" src="LaborCover.asp" frameborder="0" style="LEFT: 0%; WIDTH: 75%; TOP: 0%; HEIGHT:550px; BACKGROUND-COLOR:#CCCCCC; border:solid 0px black;"></IFRAME>
</div>
</body>
Banging my head against the wall on why I keep getting an error on the ie.document.all
Any help would be greatly appreciated.

CSS selector:
Piggybacking of the answer in the comment you can also use a CSS selector of #DirectZip.
This read as element with id of DirectZip. # means id.
CSS query:
VBA:
You use the .querySelector method of document to apply the CSS selector:
.document.querySelector("#DirectZip")

Related

Stuck in dependent drop down menu

I got stuck while creating a dependent drop down menu in react. I am trying to make a form in which user can select three options through the drop down menu respectively and based on the options selected the 4th field which is a disabled text field will be populated with the appropriate result.
This is my code.
<div className="col-md-4">
<label htmlFor="inputEmail4" className="form-label">District</label>
<select className="form-select" value={selectedDistrict} onChange={handleDistrict} aria-label="Select District" >
<option value="Select District">Select District</option>
<option value={Data.data[0].DISTRICT}>{Data.data[0].DISTRICT}</option>
</select>
</div>
<div className="col-md-4">
<label htmlFor="inputPassword4" className="form-label">Assembly Constituency Number & Name.</label>
<select className="form-select" value={selectedConstituencyNameandNumber} onChange={handleConstituencyNameandNumber} aria-label="Select Assembly Constituency Number & Name." >
<option style={{"display": "block"}} value="Select Assembly Constituency Number & Name.">Select Assembly Constituency Number & Name.</option>
{selectedDistrict && acBooth.map((acBooth, index) => (
<option key={index} value={acBooth['AC No & Name']}>{acBooth['AC No & Name']}</option>
))}
</select>
</div>
<div className="col-md-4">
<label htmlFor="inputEmail4" className="form-label">Booth No.</label>
<select className="form-select" value={selectedBoothNumber} onChange={handleBoothNumber} aria-label="Select Booth No." >
<option value="Select Booth No.">Select Booth No.</option>
{selectedDistrict && partNumber.map((item, index) => (
<option key={index} value={item["Part No"]}>{item["Part No"]}</option>
))}
</select>
</div>
This is the code for 3 drop down menu. I want to execute a function which takes two parameter from the selected options in drop down menu and then display the output in the blank text field whose code is given below.
<div className="col-md-4">
<label htmlFor="inputEmail4" className="form-label">Booth Name</label>
<input type="text" disabled className="form-control" value={boothName} onChange={()=>{
const newName = getBoothName(selectedConstituencyNameandNumber, selectedBoothNumber);
setBoothName(newName);
console.log(newName);
}} id="inputUID" />
</div>
These are the function which I have written. It is working properly in the backend but I am unable to get the output in frontend.
const getBoothName = (acNo, partNo) => {
const boothName = Data.data.filter((item) => {
return item["AC No & Name"] === acNo && item["Part No"] === partNo
})
return boothName[0]["Part Name English"]
}
const [selectedDistrict, setSelectedDistrict] = useState('');
const [selectedConstituencyNameandNumber, setSelectedConstituencyNameandNumber] = useState('');
const [selectedBoothNumber, setSelectedBoothNumber] = useState('');
const handleDistrict = (e) => {
setSelectedDistrict(e.target.value);
}
const handleConstituencyNameandNumber = (e) => {
setSelectedConstituencyNameandNumber(e.target.value);
}
const handleBoothNumber = (e) => {
setSelectedBoothNumber(e.target.value);
}
A help is really appreciated.
The onChange function of your Input Textfield should be on the 3rd Select field. After that on change of your third dropdown it will setBoothName(newName) and your value will be set in the input textfield.
<div className="col-md-4">
<label htmlFor="inputEmail4" className="form-label">
Booth No.
</label>
<select
className="form-select"
value={selectedBoothNumber}
onChange={handleBoothNumber}
aria-label="Select Booth No."
>
<option value="Select Booth No.">Select Booth No.</option>
{selectedDistrict &&
partNumber.map((item, index) => (
<option key={index} value={item["Part No"]}>
{item["Part No"]}
</option>
))}
</select>
</div>
Change handleBoothNumber function in your code like this
const handleBoothNumber = (e) => {
setSelectedBoothNumber(e.target.value);
setBoothName(getBoothName(selectedConstituencyNameandNumber, selectedBoothNumber));
}

How can I add selected attribute to option that I select?

When I select an option, I want to remove selected attribute from old one and add it to option I selected.
HTML Code:
<label>Gender</label>
<select id="gender" name="gender" class="form-control" onchange="redirect()">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="any">Any</option>
</select>
JS Code:
<script>
$("#gender").on("change", function redirect() {
// const queryStr = "gender=any&platform=any"
// const usp = new URLSearchParams(queryStr)
// console.log(usp)
url = window.location.href.split("?")[0] + "?gender=" + this.value + "&platform=<%=platform%>"
location.replace(url)
})
</script>

HTML DOM Select not working as expected on lit-html

I'm not sure if there's something wrong with my code or it's an existing bug with lit-html?
I'm trying to get value of the selected item when button is clicked.
number.js
<select class="form-control" name="number">
<option ?selected=${this.number === 1} value="1">One</option>
<option ?selected=${this.number === 2} value="2">Two</option>
<option ?selected=${this.number === 3} value="3">Three</option>
</select>
<button type="button" #click=${getSelectedValue}>Get Selected Value</button>
getSelectedValue() {
const selectOptions = this.querySelector('select[name="number"]');
const selectedValue = selectOptions.options[selectOptions.selectedIndex].value;
}
I've tried selectOptions.value but I still can't get the selected value.
Note that, I've added createRenderRoot() {return this;} to disable the shadowDOM.

how to get data from body parser in array using node js?

Here I'm having no_of_devices which has three fields 'macAddress', 'useWith' and 'type' in a row, the count of row depends upon the number of devices selected from select field, so I'm using body-parser and i want to get all the row data which has name generated using for loop so all the rows having macAddress will have name='macAdd0',name="macAdd1" etc same goes with 'type' and 'useWith' field.
HTML
<select id="noOfDevice" class="form-control" name="noOfDevice" onchange="getDeviceCount(this)">
<option selected value="0">Select</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
</select>
Javascript
<script>
var macAdd;
var useWith;
var type;
var noOfDevice = req.body.noOfDevice;
for (var i = 0; i < noOfDevice; i++) {
var k = i.toString();
macAdd[i] = req.body.macAdd[i];
useWith[i] = req.body.useWith[i];
type[i] = req.body.type[i];
//console.log(req.body.macAdd);
process.deviceManger(macAdd[i], useWith[i], type[i]);
console.log('Device' + i + 'Details Update');
}
function getDeviceCount(sel) {
console.log("No of Device:" + sel.value);
var currCount = sel.value;
var div = document.createElement("div");
for (var i = 0; i < currCount; i++) {
div.setAttribute('id', 'addElements');
div.innerHTML += '<div class="row"><div class="form-row"><div class="form-group col-md-3"><label for="inputCity">Mac Address</label><input type="text" class="form-control" id="macAdd" name="macAdd' + i + '"></div> <div class="form-group col-md-3"><label for="inputState">Type of Device</label> <select id="inputState" class="form-control" name="deviceType' + i + '"> <option selected>Select</option> <option value="Irys Slate">Irys Slate</option> <option value="Irys Sling">Irys Sling</option> <option value="Irys Swing">Irys Swing</option> </select> </div> <div class="form-group col-md-3"> <label for="inputState">Use with</label> <select id="inputState" class="form-control" name="useWith' + i + '"> <option selected>Select</option> <option value="All">All</option> <option value="Nconnect">Nconnect</option> <option value="Tiara">Tiara</option> <option value="Corona">Corona</option> <option value="TiaraMini">TiaraMini</option> <option value="Nconnect+Tiara">Nconnect+Tiara</option> <option value="Nconnect+Corona">Nconnect+Corona</option> <option value="Nconnect+TiaraMini">Nconnect+TiaraMini</option> </select> </div> </div> </div>';
document.getElementById("devices").appendChild(div);
}
}
</script>

how to scrape through drop down menu using requests

I want to scrape through web pages that are selected from drop down as shown below
<h1>Scraping Test</h1>
<form action="/tests/scraping" method='post'>
<input type="hidden" name="csrf_token" value="1499585369##d2d1570f820aec0589b3bd5f4ab4e7df913e25ff"/>
<table>
<tr>
<td>Select Ward: </td>
<td>
<select name="ward">
<option value=''>-- select --</option>
<option value='DHANLAXMICOMPLEX'>DHANLAXMICOMPLEX</option>
<option value='POTALIYA'>POTALIYA</option>
<option value='ARJUNTOWER'>ARJUNTOWER</option>
<option value='NEWCLOTHMARKET'>NEWCLOTHMARKET</option>
<option value='CHANAKYAPURI'>CHANAKYAPURI</option>
<option value='BHAIKAKANAGAR'>BHAIKAKANAGAR</option>
<option value='RADHASWAMYROAD'>RADHASWAMYROAD</option>
<option value='SATADHAR'>SATADHAR</option>
<option value='AMRUTAVIDYALAYA'>AMRUTAVIDYALAYA</option>
<option value='AGARWALTOWERS'>AGARWALTOWERS</option>
<option value='RANNAPARK'>RANNAPARK</option>
<option value='IIM'>IIM</option>
<option value='VEJALPURWARD'>VEJALPURWARD</option>
<option value='GITAMANDIR'>GITAMANDIR</option>
</select>
</td>
<td><input type="submit" value="Search" class="search"/></td>
</tr>
</table>
how to request a webpage from that drop down menu and there is also a search button
my code
import requests, csv
from lxml import html
def get_all_pages():
payload = {'value':'DHANLAXMICOMPLEX'}
url = requests.get('https://recruitment.advarisk.com/tests/scraping',data=payload)
print(url.text)
There is a token value which you can get from this HTML element
<input type="hidden" name="csrf_token" value="1499585369##d2d1570f820aec0589b3bd5f4ab4e7df913e25ff"/>
and use in your request. Try to use below code and let me know in case of any issues
import lxml.html
import requests
url = "https://recruitment.advarisk.com/tests/scraping"
s = requests.session()
r = s.get(url)
source = lxml.html.document_fromstring(r.content)
token = source.xpath('//input[#name="csrf_token"]/#value')[0]
headers = {'Referer': 'https://recruitment.advarisk.com/tests/scraping'}
data = {'csrf_token': token, 'ward': 'DHANLAXMICOMPLEX'}
print(s.post(url, data=data, headers=headers).text)

Resources