Change zoom setting of IE for web-scraping with VBA - vba

I am trying to do web scraping with VBA and have a following error:
Do
Dim driver As New webdriver
driver.Start '"ie"
Then
I fixed "internet option" setting and reset settings to default. I also checked registry settings, but it was already set to 100%.
However, every time I open IE, its zoom ratio is set to 200%.
What codes can I add in VBA, or which setting should I change?

Maybe this is not a good solution but I connected the PC to the external monitor, which solved the problem.

Related

Open Edge in IE Mode using VBA

I am trying the #longvh registry solution (Automating Edge Browser using VBA without downloading Selenium) and have a question: Do I need to change the VBA code to open Edge in IE Mode, rather than IE? If so, can anyone provide an example of that? Thanks!
Do I need to change the VBA code to open Edge in IE Mode, rather than IE?
There is no COM interface available for the Edge browser. Microsoft has not provided any way to automate the Edge browser using VBA automation.
So, there is no way to fetch the already opened instance of the Edge browser and retrieve elements with the help of VBA.

Selenium NoSuchDriverError IE Protected mode VBA

I'm getting an error trying to launch IE w/ Selenium Web Driver.
Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver).
I know one fix is to resolve the actual problem, but I'm more concerned with making my code able to work around the issue.
I've seen this fix in C#, but I don't know how I can use this in VBA. Any pointers? --> https://stackoverflow.com/a/13384197/5079799
var options = new InternetExplorerOptions;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
var driver = new InternetEplorerDriver(options);
From the description, it looks like you are using the IE VBA Automation approach but to fix the issue you are referring to the Selenium Web Driver solution.
You will not be able to set capability in the IE VBA Automation.
To fix this issue, you need to go to the Internet options-> Security tab.
Whether checked or unchecked the Enable Protected Mode option for all the zones. Keep the same value for all zones.
It will fix the error and you can continue to run the code.
Let me know if I misunderstand something from your description, I will try to correct myself.

Using Selenium VBA: How to access a Chrome window that was opened by another app?

I work with Excel VBA Selenium under Windows 10.
I want to access a Chrome window that has previously been opened by another app and of whose name only the first part is known, the rest is a code that changes each time it is created. It is open together with other tabs in the active Chrome browser.
In order to start Chrome with Selenium, all I know to do is
Set dr = New ChromeDriver
This creates an Object "dr". When I look up the properties of dr, the property "Windows" shows the value
"BrowserNotStartedError / Browser not started. Call Get, Start or StartRemotely first."
Start or get both create a new Chrome instance which does not allow me to access windows in the already open instance.
I tried to use this code without "New", but this does not work.
I have not found any hint on how to work on the existing instance of Chrome. Is it possible at all?
If not, how else could I access any existing window? The URL is unique and can only be created by the 3rd party app for security reasons. If I try to copy the URL to the new Chrome instance I get an authentication error, so this is not an option.
This web page basically contains a menu that allows me to download certain data safely, which I want to automate.
Any help is appreciated.
Actually, there is a way to do it with Selenium driver for Chrome.
Locate your chrome.exe directory and copy and append the line below into the target bar.
--remote-debugging-port=9222 (Include the preceding space).
Then copy the following code into a vba module, execute it, and it will allow you to manipulate the existing chrome session that you created.
Dim chromeBrowser As Selenium.ChromeDriver
Sub existingChromeSession()
Set chromeBrowser = New Selenium.ChromeDriver
chromeBrowser.SetCapability "debuggerAddress", "localhost:9222"
chromebrowser.Get("https://www.google.com")
End Sub
My question has been resolved.
With a Selenium driver for Chrome, it is not possible to access Chrome tabs that have not been created with Selenium.
According to QHarr, it could be done by using shell/internet explorer to grab a handle on existing IE windows. In this case, of course, the app would have to create the HTML file with IE, i.e. the default browser would have to be IE.

Internet Explorer 11 Browser session becoming corrupt

I'm having an issue with a random set of users running Windows 10 and IE11. When the issue occurs the user are in an IE 11 browser session and will see among other things that selected div sections will scroll text but the textboxes and dropdowns will remain static within that div.
The current fix is to start a new browser session not just a new window. Currently this only occurring in about 15-20 out of 700 users. Pages are running with doc mode Edge and user agent default.
I realize this is a rather sparse explanation but that is what I have so far. Does anyone have a suggestion as to what could be causing the issue or a tool that would allow further investigation into the browser session?
From your description, I assume that this issue is not related with website and issue is with IE browser.
I suggest you to check for latest Windows and IE related updates. If any new updates are available than try to install new updates and again check for the issue.
If no any new updates available than try to reset the Internet Explorer browser to check whether it fix the issue or not.
If issue persist than you can try to unchecked the Internet Explorer option from Turn Windows features on or off and again try to check that option to add the IE again.
Let us know about your testing results. If issue persist than we can try to provide further suggestions.

Why I can programmatically access only the first loaded page?

I have very weird issue with some VBA code. The code is InternetExplorer automation and it's really simple: I just need to load page, enter credentials and click on the button on another page (after successful login).
But... My code is not working (but only on one of my machines on AWS). On my local machine this code works fine.
The weird thing is that it seams I have access only to the Document property of the first loaded page (where I need to enter login/password). I mean from MyBrowser.Document property I can see all INPUT fields when I load start page. But after successful login (the IE window is visible) I see same INPUT fields from MyBrowser.Document property! Also (as I said) I have no issues with this code on another maching.
IE Protected mode is disabled (this is IE 11). I think this is some kind of security issue but I can't locate it by myself...
Here is my code:
'MyBrowser is IE instanse
'Here I'm loading start page and input login/password
'Next the browser show me another page where I need to click a button
'But Debug messages show me input fields for the first Form!
Application.Wait (Now + TimeValue("0:00:05"))
Do
DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
For Each myHTML_Element In HTMLDoc.getElementsByTagName("INPUT")
If myHTML_Element.Type = "submit" And myHTML_Element.Name = "BUTTONNEWJOBS" Then myHTML_Element.Click: Exit For
Debug.Print myHTML_Element.Name
Next
UPDATE
I don't know why but my browser object is always Busy that's why I get old page HTML. I tried to .Stop it but with no luck.
I don't have answer for IE11 automation, just a hint for a path you may choose to walk.
Another Stack Overflow question Getting source of a page after it's rendered in a templating engine? provides some browser automation options.
One of the mentioned tool has currently broken support for IE11 due to a IE11 behavior change, see http://docs.seleniumhq.org/about/platforms.jsp#browsers. The blocking issue has some configuration hints you may find useful.
In my opinion Internet Explorer was ALWAYS the least reliable tool both from the point of view of rendering compatibility, programmability and even the automation problems accross different versions. And although it had improved over the years Internet Explorer is still better to be avoided (from programmer's point of view). Today it is luckily not the only tool available.
So if you just need to get the work done, there are other browsers or browser-like tools that you can use.
If you MUST use IE then you should get your answer at the Internet Explorer Dev Center → Community → Developer forums
EDIT (after comments)
By the symptoms in your question it looks like the browser object is busy because of some dialog box (perhaps a security prompt) is being show to the user. Some links from Google that may help:
required IE configuration from the selenium browser automation engine - https://code.google.com/p/selenium/wiki/InternetExplorerDriver
how to disable Internet Explorer Enhanced Security Configuration - http://4sysops.com/archives/four-ways-to-disable-internet-explorer-enhanced-security-configuration-ie-esc/
Internet Explorer Security Zones and Compatibility View - https://help.blackboard.com/en-us/Learn/9.1_SP_14/Administrator/030_Browser_Support/030_Browser_Support_IE_Issue
set of dialogs that can be manipulated by the iMacros Internet Explorer automation toolkit - http://wiki.imacros.net/Browser_Automation#Dialog_Manager
Rewriting ~1000 lines of code to use another automation interface (or browser) and asking for help at the Microsoft's Internet Explorer Dev Center are IMO still valid options
Based on your following statement
I see same INPUT fields from MyBrowser.Document property!
it would seem that the page hasn't fully loaded. Perhaps it is loading data via AJAX and clicking the submit button shows the exact same page (which would explain why you were seeing the same INPUT fields) while waiting for a response from the server.
An easy way to test this is to wait for a longer period of time (e.g. 30 seconds) and ignoring the value of the browser ReadyState. However a better way would be looping until you find a element on the successful page that isn't on the first page, with a possible timeout of maybe 30 seconds.
I've used Selenium to do some automation and ran into similar problems and had to resort to using Implicit Waits but I'm not sure if VBA as such a feature (as I don't know VBA)