I am new to Selenium and I am trying to upload a file using WebDriver. Here I am trying to click browse button using dom element as follows:
selenium.type("document.forms['UploadForm'].elements['browsebutton']",file.getAbsolutePath());
But since the approach did not work am trying to hit browse button using WebDriver element as below: How can i change my dom element to xpath or css selector as below?
driver.findElement(By.cssSelector("input[type=\"file\"]")).click();
I cant write xpath as
selenium.click("xpath="//input[@name='uplaod' and @value='browsebutton']");
since i have multiple browse buttons with same name and value.. So i need to pick using dom element itself. How do i do it?
Thanks in advance for help.
Dominik i have tried using the below xpath since there is no name attribute:But not working
String upload="(//input[@name='bulkUnBlockUploadForm' and @value='requestFile'])[2]";
String button="(//input[@name='bulkUnBlockUploadForm' and @value='process'])[2]";
I tried using id as well:Not working
String upload="(//input[@id='content' and @value='requestFile'])[1]";
String button="(//input[@id='content' and @value='process'])[1]";
The issue is in my jsp,i have 2 browse buttons s with same id and same value,but different form.I have 2 submit buttons for each of browse buttons with same id and same value,but different forms.So when am using the above approaches its hitting both the submit buttons
This can upload a file, it is work for me.