ajitjaiswal50 / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
0 stars 0 forks source link

Unable to open the URLs in the excel file using chrome #128

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system : Win 7
.Net Framework version :
Office Version : 2010
SeleniumWrapper version : 1.0.23.0

What is your issue ?
I am trying to open a list of URLs with column A but the first tab gives, 
'www.google.com/www.amazon.com' and 'about:blank' for the rest of the tabs.

For example:
URLs (Header)
www.facebook.com
www.yahoo.com
www.google.com
www.amazon.com

Code:

Private Sub cmdLoadURLs_Click()

Dim selenium As New SeleniumWrapper.WebDriver

Dim intRowPosition As Integer
Dim keys As New SeleniumWrapper.keys

selenium.Start "chrome", "http://www.google.com"
selenium.setTimeout ("120000")
selenium.setImplicitWait (5000)
intRowPosition = 2
selenium.Open Sheet1.Range("A" & intRowPosition)

intRowPosition = intRowPosition + 1

While Sheet1.Range("A" & intRowPosition) <> vbNullString
    selenium.executeScript "window.open()"
    'selenium.SendKeys keys.Control & "t"
    selenium.Open Sheet1.Range("A" & intRowPosition)
    intRowPosition = intRowPosition + 1
Wend

End Sub

Reference: 
http://www.makeuseof.com/tag/how-to-automate-firefox-or-chrome-with-vba-and-sele
nium/

Thank you!

Original issue reported on code.google.com by jonkh...@gmail.com on 10 Jan 2015 at 4:54

GoogleCodeExporter commented 8 years ago
That's because the Urls you're providing are not valid (the protocol is missing 
in front).
When the protocol is missing, the root Url defined by the start command is 
added in front.
This is why you get "http://www.google.com/www.amazon.com" in the address.

Try these Urls instead:
 https://www.facebook.com
 https://www.yahoo.com
 https://www.google.com
 https://www.amazon.com

Or add the protocol before calling the open command:
 Dim r
 For Each r In Range(Sheet1.Cells(2, 1), Sheet1.Cells(2, 1).End(xlDown))
    selenium.executeScript "window.open()"
    selenium.Open "https://" & r
 Next r

Original comment by florentbr on 10 Jan 2015 at 2:56

GoogleCodeExporter commented 8 years ago
Hi florentbr

Thank you for your reply.

I tried using firefox and it managed to open 3 tabs instead of 4 tabs. I 
noticed that the 2nd tab first's address is yahoo then it changes to google. it 
is kind of weird. (Please refer to the attached screenshot, firefox.png)

As for chrome, it opens up 4 tabs. first tab is amazon because it went through 
all the URLs on the same tab.  (Please refer to the attached screenshot, 
chrome.png)

Thanks for the insight!

Original comment by jonkh...@gmail.com on 10 Jan 2015 at 3:20

Attachments:

GoogleCodeExporter commented 8 years ago
You need to set the window on which the driver will operate before opening the 
Url:
 wd.executeScript "window.open()"
 wd.switchToWindow -1   'Switch to the last window
 wd.Open ...

Original comment by florentbr on 10 Jan 2015 at 3:51

GoogleCodeExporter commented 8 years ago
Hey florentbr

Thank you for the help!

The line, 'wd.switchToWindow -1' helps to ensure that each website is opened in 
each tab for chrome. (Please refer to the attached screenshot, chrome2.png)

However, it does not work for firefox unless I used this 
'selenium.executeScript "window.open()"' instead of this code, ' 
selenium.SendKeys keys.Control & "t"'  which opens up the 3 tabs instead of 4 
tabs. Also, 2nd tab first's address is yahoo then it changes to google.

Hopefully this thread will be useful for someone who want to work on firefox 
later since it works for chrome browser.

Once again florentbr.

This will be good: 
http://selenium.googlecode.com/svn-history/r5810/webdriver/javadoc/org/openqa/se
lenium/remote/server/handler/SwitchToWindow.html

Thank you for the help.

Original comment by jonkh...@gmail.com on 11 Jan 2015 at 12:07

Attachments: