How to upload file using selenium on linux machine with headless browser? - selenium

Without Send keys, i have tried with
AutoIT and Robot which is not working for me.
exeCompile autoit file :
ControlFocus("Register Free at Monster India to Upload Resume and Apply Jobs Online - Google Chrome","","Intermediate D3D Window1")
Sleep(2000)
ControlSetText("Open","","Edit1",$CmdLine[1])
ControlClick("Open","","Button1")
AutoIT :
ProcessBuilder processBuilder = new ProcessBuilder(Constants.TestAutoItScripFileUpload,Constants.TestPdfFile);
processBuilder.start();
Is there any way to handle file upload on linux ?

Related

How to automate upload file with double click without using send keys in selenium java?

Trying to automate using the below code but not working
Actions actions = new Actions(driver);
fileupoladbtn.sendKeys(System.getProperty("user.dir") +"/Images/zoom_out.jpg");
actions.dragAndDrop(fileupoladbtn, fileupoladbtn1);
what I could understand from your short described question , you need to interact with windows file upload which is not handled by selenium , you need to use auto it scrip and call that in your selenium script.you can download Auto it and SCiTE which is the editor.
below is the autoit file upload script -
Sleep(1000)
ControlFocus("Open","","Edit1")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Send("{Backspace}")
Sleep(1000)
Send($CmdLine[1])
Send("{Enter}")
Sleep(2)
ControlClick("Open","","Button1")
It will be saved when you go to tools and compile it in autoit editor, note the name from here.
once action to popup file upload is done, and Window handler to file upload is visible call above script.
for Java
Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe");
for Python
subprocess.Popen('C:\\Handle\\FileUpload.exe '+File_path, shell=True)
More Details
https://www.autoitscript.com/site/autoit/downloads/
https://www.guru99.com/use-autoit-selenium.html

How to get rid of the BrowserStack Local extension popup using ChromeDriver Chrome and Selenium

Am just new to automation and trying to automate browserstack. And i successfully logged to browserStack and passed the credentials and clicked on adding chrome extension . There comes the popup and am unable to get the selector for the buttons in the popup.Did any body face across this issue.
Am using an internal tool to automate,behind the scene i guess its using selenium.
Can anybody help me to find the selectors for the popup in browser stack.
Will attach the screenshot
Any help will be hihly helpful,since its a big blocker for me
If you want to Automate a local hosted URL or internal URL you will have to use BrowserStack Local testing feature. There is no need to add this extension.
There is one documentation on How to Perform local testing. All the steps are mentioned in the documents.
BrowserStack Automate Local Testing
If your usecase involves adding the BrowserStack Local or any other extension as a part of your Test Strategy you need to do it programatically.
You can find a couple od relevant discussions in:
How to install extension permanently in geckodriver
How to load extension within chrome driver in selenium with python
Alternative
As an alternative you can enable Enabling Local Testing either programatically through language bindings or through the command-line interface as follows:
Using language bindings:
Java:
import com.browserstack.local.Local;
# creates an instance of Local
Local bsLocal = new Local();
# replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
HashMap<String, String> bsLocalArgs = new HashMap<String, String>();
bsLocalArgs.put("key", "<browserstack-accesskey>");
# starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs);
# check if BrowserStack local instance is running
System.out.println(bsLocal.isRunning());
#stop the Local instance
bsLocal.stop();
Steps for using command line:
Download the matching binary for your os: OS X / Linux 32 bit / Linux 64 bit / Windows
Untar/Unzip the binary to a folder/directory on your system.
Open your command-line interface and navigate to the folder containing the Local binary.
Run the binary using the following command:
//OS X/Linux
./BrowserStackLocal --key ACCESS_KEY
//Windows
BrowserStackLocal.exe --key ACCESS_KEY
Configure tests to run with Local Testing connection as follows:
caps.setCapability("browserstack.local", "true");

automate image upload from windows explore with selenium and AutoIT

I have to automate a scenario like a upload an image from windows explorer to TinyMCE component using Selenium. Since Selenium does not support OS control, I used AutoIt to upload the image.
AutiIt sets the image path to "File name" and seems like it clicks on 'Open' button as well. But the image is not loading to my "source" field.
Here is my Selenium command:
Runtime.getRuntime().exec("C:/XXXXX/src/test/resources/uploadImage.exe");
// Path of the AutoIT script file
AutoIT script:
WinActivate("Open")
Send("C:\LCNGProjects\Screenshots\Images\GifImage1.gif")
Sleep(5000)
Send("{ENTER}")
Refer the attached screenshot
Not sure if I have got the questions correct, Did you compile the script.
Can you please go through link below for script compilation and step by step info how to upload a file.
https://www.guru99.com/use-autoit-selenium.html
You do not need to use AutoIt. Auto will make your script dependable on windows machine only.
Instead of it find element using locator(i.e. xpath) of upload button which is having tag as type="file". Now pass this simple sendKeys with absolute path of your image in your machine like below:-
button2.sendKeys("C:\\UsersDesktop\\logo\\Summit-Logo-900px.png");
Or use
System.getProperty("user.dir"));
Append the path of file exluding your project path and filename inside your project
Example :-
button.sendKeys(System.getProperty("user.dir")+"\\logo\\Summit-Logo-900px.png");
below link contains more option to upload file like below :-
Using SendKeys command.
Using AutoIt scripting.
Using Jacob com interface.
http://www.techbeamers.com/handle-file-upload-selenium-webdriver/#h3
Hope it will help you :)
I'm not going to add full source code here. You can call the AutoIT script using this command inside your test case.
// Call to AutoIT script to upload the image
Runtime.getRuntime().exec("C:\\xxxxx\\src\\test\\resources\\uploadImage.exe");
AutoIT Scrip
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1","C:\xxxx\Images\jpgImage")
ControlClick("Open","","Button1")
For more information refer the following link
https://www.guru99.com/use-autoit-selenium.html

Script to upload a file,in selenium IDE

Script to upload a file,in selenium IDE or
How to automate uploading a file using selenium
You can use
selenium.type("xpath of text box","path of your file")
command=type
target=xpath_of_text_box
value=Path_of_your_file
example:
selenium.type("id=cvfile", "D:\\Automation\\resume.doc");

Is there any way to find out if selenium is running using code?

I want to find out if selenium is running and if it isn't then call a bat file to start it. Is it possible to find out if selenium standalone is running?
If you are using Java, you can invoke the server programmatically -
RemoteControlConfiguration settings = new RemoteControlConfiguration();
File f = new File("C:\\selenium-profile");
settings.setFirefoxProfileTemplate(f);
settings.setReuseBrowserSessions(true);
SeleniumServer seleniumserver=new SeleniumServer(settings);
seleniumserver.boot();
setUp("http://www.google.com", "*firefox");