Issue
I'm getting attached error in SeleniumVBA while trying to write a code to upload a file in internal website. Could you please help how can i rectify it.
I'm trying to login into a website and upload a file from a source to download the data, but when i am sending path to file as sendkeys and running the code, It gives me an error
Its the last line where i am asking to send keys to upload file, which is causing an error.
Option Explicit
Dim mydriver As New Selenium.WebDriver
Sub openrtweb()
Dim login_ As String
Dim password_ As String
Dim file_to_send As String
Dim FindBy As New Selenium.By
Dim button As Selenium.WebElement
Dim upload_ As Selenium.WebElement
mydriver.Start "chrome"
mydriver.Get "http://rtweb/login/"
login_ = Sheet1.Range("B1").Text
password_ = Sheet1.Range("B2").Text
file_to_send = "D:\Ecommerce\Excel Experiments\SOH\1. TBL Flash Sales sha- STK.txt"
AppActivate ("CHROME")
mydriver.FindElementByName("ctl00$ContentPlaceHolder1$txtUsername").SendKeys login_
mydriver.FindElementByName("ctl00$ContentPlaceHolder1$txtPassword").SendKeys password_
mydriver.Wait 1000
mydriver.FindElementByName("ctl00$ContentPlaceHolder1$btnLogin").Click
mydriver.Get "http://rtweb/cr-mis-report/"
'mydriver.FindElementByName("UploadFile2", 1000).Click
'mydriver.FindElementByXPath("//input[@name='UploadFile2']", 1000).SendKeys file_path
Set button = mydriver.FindElementByCss("//input[@name=""UploadFile2""]")
button.SendKeys file_to_send
'"//input[@name='UploadFile2']",1000
End Sub
Solution
Your problem is here:
Set button = mydriver.FindElementByCss("//input[@name=""UploadFile2""]")
"//input[@name=""UploadFile2""]"
is XPath expression, not CSS Selector.
So, please change it to:
Set button = mydriver.FindElementByCss("input[name='UploadFile2']")
Or
Set button = mydriver.FindElementByXpath("//input[@name='UploadFile2']")
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.