'Selenium / C# Challenge / Threaded / Multiple drivers for each tab on the same browser opened by Selenium
As a preamble: I have an Excel-VBA workbook which can open an IE browser, login to a website with username,password, set up half a dozen webpages in tabs, and interact with these pages to do various tasks eg enter data into forms, read the result, and regularly repeat the refresh of a page to extract desired info.
What it cannot do is these tasks in separate threads (as far as I know) - which is what I need for Version 2.0 ie automatic refresh of several pages "at the same time" independent of the other processes running; and entry of data into the forms on the other pages based on the downloaded info.
So currently I am experimenting with Visual C# (as it seems to have the thread capabilities) and Selenium (for its browser control), with the intent to recreate the same functionality of the VBA application and add the necessary threading and other fancy functions I can think of.
But of course, I have encountered some challenges and so I place these questions before you in the hope that someone can assist.
I have managed to open say 3 web pages in separate windows - having to log in each time - but only the last window opened is remembered by the website - if I refresh window 1 or 2, the pages revert to the login screen again - this doesn't seem to happen for manually opened browser instances (eg in Edge) - 1st login is remembered and not needed for the 2nd or 3rd instances.
Question 1: Is this normal or have I miscoded in some way ? do I have to open all the pages in tabs in the same browser window ?
Question 2: I was hoping to avoid having multiple windows opened, preferring for neatness to have all the pages on tabs in the same browser; but is this possible ? I am thinking that for each thread, a separate Selenium driver will be needed as one thread cannot SwitchTo the page it needs whilst another thread is using the same driver for it's own page.
Does anyone have any opinions on this ? eg "possible"/"not posssible" or better still "yes you can and here's the code..." lol
Update I have code adapted from a YouTube video - it sort of works
dBal = new EdgeDriver(EDGE_DRIVER_DIR);
<Login code for dBal>
dPos = (EdgeDriver) dBal.SwitchTo().NewWindow(WindowType.Tab);
dOrd = (EdgeDriver) dBal.SwitchTo().NewWindow(WindowType.Tab);
dBal.SwitchTo().Window(dBal.WindowHandles[0]);
This opens a browser, with 3 tabs, login only occurs once,
but it does not seem as though dPos & dOrd are independent entities.
Perhaps dPos and dOrd are only references to dBal ?
eg to change dPos page, the code dPos.SwitchTo().Window(dPos.WindowHandles[1])
needs to be used instead of dPos.SwitchTo().Window(dPos.WindowHandles[0])
but shoudn't dPos only have 1 window handle ?
Concerned that in a thread, this code won't work - eg changing dPos to new page/refreshing must not in the background change dBal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|