Selenium VBA Excel stop browser closing - vba

hi guys i need help with my vba code, i just want the code to finish and leave the window open
Sub BCAuto()
Dim obj As New WebDriver
obj.Start "Chrome", "https://www.google.com"
obj.Get "https://www.google.com"
obj.Window.Maximize
End Sub

Related

Open Chrome with options

With this script I open Chrome in Selenium VBA
Public Sub browser_open()
Set bot = New ChromeDriver
bot.Start "chrome", "http://some_site"
bot.get "/"
End Sub
Is it possible to open Chrome using the options --kiosk-printing, so that printing takes place without dialogue?

Printing a webpage using selenium in VBA

I am trying to print a webpage using selenium in VBA. I want the bot to be able to press control+P and then Enter on the printing dialog but keep getting an object required error. Anyone have any ideas?
Sub printing()
Dim bot As New WebDriver, controlP As Variant, enter As Variant
bot.Start "chrome", ""
bot.Get "https://www.google.com/"
controlP = (Keys.Control & "p")
enter = (Keys.enter)
bot.FindElementByXPath("/html").SendKeys (conrolP)
bot.FindElementByXPath("/html").SendKeys (enter)
End sub
I am not sure the approach you are trying is the way to achieve your goal. However, here are some points:
I think the relevant xpath should be //html.
Use Option Explicit as first line of your module code; You have a typo with conrolP which Option Explicit would have alerted you to as an undeclared variable.
You also don't need those () with SendKeys.

How to click HREF using Selenium

Trying to click a download button on Chrome using Selenium Type Library. The code below is one that I picked up off the boards but I am receiving a Syntax Error
Sub Test()
Dim bot
Set bot = CreateObject("Selenium.WebDriver")
bot.Start "Chrome", "https://www.afterpaytouch.com"
bot.get "/results-reports"
bot.findElement(By.linkText("https://www.afterpaytouch.com/images/28082019-FY2019-Results-Presentation.pdf")).click()
End Sub
I would add a reference to Selenium Type Library in VBE > Tools > References then use early bound reference, full url and apply VBA selenium basic syntax to find link by css and click
Option Explicit
Public Sub Test()
Dim bot As WebDriver
Set bot = New ChromeDriver
With bot
.Start "Chrome"
.get "https://www.afterpaytouch.com/results-reports"
.FindElementByCss("[href='https://www.afterpaytouch.com/images/28082019-FY2019-Results-Presentation.pdf']").Click
Stop '<delete me later
End With
End Sub

Cannot Login with Excel VBA Selenium

So I am tryin to create a Script that will automatically login for me on this website:
https://teespring.com/login
This is my script so far:
Sub openBrowser()
'Open new browser
Set driver = New Selenium.ChromeDriver
'Navigate to Website
urlWebsite = "https://teespring.com/login"
driver.Get urlWebsite
So I have tried to enter my username with the following lines of code:
driver.FindElementByCss("").sendKeys Username
But I got an error saying element not visible
Is there any way I can still automate the login process?
thanks for your help and if you need further information I will try my best to as I am still learning how to handle vba selenium :-)
It is not visible because it is inside a form.
You need to access via form:
Option Explicit
Public Sub EnterInfo()
Dim d As WebDriver
Set d = New ChromeDriver
Const URL = "https://teespring.com/login"
With d
.Start "Chrome"
.get URL
With .FindElementByClass("js-email-login-form")
.FindElementByCss("input[name=email]").SendKeys "myEmail"
.FindElementByCss("input[name=password]").SendKeys "myPassWord"
.FindElementByCss("input[type=submit]").Click
End With
Stop '<== Delete me after inspection
.Quit
End With
End Sub

VBA Ctrl+A to select all content in a page by Selenium WebDriver

I saw a similar thread on Java but I am not familiar with that language so need a solution for VBA- suppose I want to press ctrl+A to select all content in a website using selenium:
Private Sub CommandButton1_Click()
Dim shell: Set shell = CreateObject("WScript.Shell")
Dim driver As New SeleniumWrapper.WebDriver
driver.Start "firefox", "http://www.espnfc.com/gamecast/statistics/id/376930 /statistics.html"
driver.setImplicitWait 5000
driver.Open "/"
shell.SendKeys "^a"
End sub
However this only highlights the URL. What is the best way to select all the content in the webpage and then copy it (ctrl +a and ctrl+ c)? ALso are there any references I need?
I've been looking for a good guide to selenium keys on google but have been struggling so far...
Have you tried .getBodyText? I tested it once and it worked fine:
Private Sub CommandButton1_Click()
Dim shell: Set shell = CreateObject("WScript.Shell")
Dim driver As New SeleniumWrapper.WebDriver
dim Body as string
driver.Start "firefox", "http://www.espnfc.com/gamecast/statistics /id/376930 /statistics.html"
driver.setImplicitWait 5000
driver.Open "/"
Body=driver.getBodyText
End sub
You can then 'paste' into a spreadsheet via cells(1,1)=Body or back into a webpage element via driver.findElementById("ElementNameHere").SendKeys Body