How to create batch file which opens an website e.g. gmail.com and enters user name and password
i need to crea开发者_如何学Pythonte a batch file which opens a website(gmail) and enters username and password. so can anyone help me please.. Thank you.
here is the code i tried.. It opens gmail, now how can i enter username and password.
saved as Test.bat
@echo off
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE https://gmail.com
Won't let me comment, but I agree the batch is the wrong way to do this. You could do this with PowerShell though.
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
#Loads Website
C:\Progra~1\Intern~1\iexplore.exe -k http://www.gmail.com
#Enter Credentials
[System.Windows.Forms.SendKeys]::SendWait("userid{TAB}password{enter}")
You cannot do this. You can open a specific url, but you cannot enter values in a form.
You can open an e-mail adress from the command prompt, but that will open the default e-mail client, and not some webmail page. So unfortunately, it's not possible.
I don't think there's a purely-batch way of achieving your goal.
You may try to write something up, using, for example, http://jsoup.org/ . But you'll need to change your code every time there's a new specification on the page.
This can be done with Selenium. You need to write a simple Selenium JUnit test in Java. Of course, this requires that Java be installed on the computer. It would be about 20-30 lines of code. Then, you can execute the JUnit test from a batch file like so:
@ECHO off
SET username=me
SET password=mypassword
java -cp MyGmailTest.class MyGmailTest %username% %password%
timeout 10
Use selenium's firefox WebDriver with java.
http://docs.seleniumhq.org/download/
Import all the necessary webDriver librarys, and it will very simple. Something like this:
public class checkEmail{
public static void main(String args[]){
WebDriver driver = new FirefoxDriver();
driver.get("www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("your usernamne");
driver.findElement(By.id("Passwd")).sendKeys("your password");
driver.findElement(By.id("signIn")).click();
}
}
get the .class files, then make a simple batch file
@ECHO OFF
set CLASSPATH= (wherever your selenium jars are)
cd C:\where ever the class file is
java checkEmail
WITH FIREFOX:
@echo off
set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS
start https://gmail.com
echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%
echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%
echo Do Until Success = True >> %command%
echo Success = objShell.AppActivate("Mozilla Firefox") >> %command%
echo Loop >> %command%
echo WshShell.SendKeys "USERNAME HERE" >> %command%
echo WshShell.SendKeys "{TAB}" >> %command%
echo WshShell.SendKeys "[PASSWORD HERE] >> %command%
echo WshShell.SendKeys "{ENTER}" >> %command%
ping 192.0.2.2 -n 1 -w 5000 > nul
start %command%
ping 192.0.2.2 -n 1 -w 1000 > nul
del %command%
exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] }
WITH GOOGLE CHROME
@echo off
set command=C:\Users\%USERNAME%\Desktop\GMAIL.VBS
start https://gmail.com
echo Set objShell = WScript.CreateObject("WScript.Shell") > %command%
echo Set WshShell = WScript.CreateObject("WScript.Shell") >> %command%
echo Do Until Success = True >> %command%
echo Success = objShell.AppActivate("Google Chrome") >> %command%
echo Loop >> %command%
echo WshShell.SendKeys "USERNAME HERE" >> %command%
echo WshShell.SendKeys "{TAB}" >> %command%
echo WshShell.SendKeys "[PASSWORD HERE] >> %command%
echo WshShell.SendKeys "{ENTER}" >> %command%
ping 192.0.2.2 -n 1 -w 5000 > nul
start %command%
ping 192.0.2.2 -n 1 -w 1000 > nul
del %command%
exit
chance [USERNAME HERE] AND [PASSWORD] { with the [ ] }
@if (@CodeSection == @Batch) @then
@echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
%SendKeys% "{ENTER}"
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
While i myself am still experimenting and testing this batch file program on different applications, i am not sure as to the inner-workings of what this program actually does. All i know is it uses a java script installed on every windows computer to push keyboard commands to be executed. However in my experimentation i found that it could also serve as a means to fill in passwords and usernames.
@if (@CodeSection == @Batch) @then
@echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
START FIREFOX "WWW.EXAMPLE.COM"
rem the script only works if the application in question is the active window. Set a timer to wait for it to load!
timeout /t 5
rem use the tab key to move the cursor to the login and password inputs. Most htmls interact nicely with the tab key being pressed to access quick links.
%SendKeys% "{TAB}"
rem now you can have it send the actual username/password to input box
%SendKeys% "username{TAB}"
%SendKeys% "password{ENTER}"
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
check this
精彩评论