简体   繁体   中英

Selenium VBA (excel) to search text from Excel in web page

I am new to selenium VBA and I am using selenium web drive to find the member's name in the web page and update the information for that record.

I can search the name and click the record by using the below code:

bot.FindElementByXPath("//*[@class='x2h' and text()='Peter Melo']").Click

I would like to replace Peter Melo by using the Excel spreadsheet and Peter Melo is in the ActiveSheet Cell A1

So I tried to replace Peter Melo ActiveSheet.Range("A1").Value by using the above code but it doesn't work.

May I know how can I use the name available in Excel and search it in the Web?

Thanks in advance for any help or advice I might receive!

Can you try using Sheet1.Cells(1, 1).Value instead of ActiveSheet.Range("A1").Value . Range method usually used for a Range.its not the right approach to pass the single cell value.However ActiveSheet.Range("A1").Value should work. but if its not working then I assume in the active sheet it might not have any value. Can you try

Worksheets("Sheet1").Range("A1").Value

Where Sheet1 is the Sheet where you store "PeterMello". But this should definitely work Sheet1.Cells(1, 1).Value

Your code should be

bot.FindElementByXPath("//*[@class='x2h' and text()='"+Sheet1.Cells(1, 1).Value+"']").Click

or

bot.FindElementByXPath("//*[@class='x2h' and text()='"+Worksheets("Sheet1").Range("A1").Value+"']").Click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM