0

I am using python and selenium to do a load test. What I need to do is search a system and display its event content. Currently I have :

test_url = base_url + args.system + event_page_url_addon

The issue is that if I have 5 threads of this event going on, they have the same URL because they are all looking for the same system, and I have 5 different tabs all with the same URL. My question how do refer to each tab/thread? ( tab1, tab2....) If I manipulate the URL by adding an index number at the end, then the site became unsearchable.

Any help is appreciated.

2
  • get the window handles... Selenium has a method for getting the current window handle, getting all window handles and switching the driver between those handles. This will only be a single thread... you can use one thread per driver per browser... but Selenium is not good for load testing. There are other tools for that. Commented Jul 20, 2021 at 20:57
  • Hi pcalkins, thanks very much for the help. What is a good tool to do load tests of a web page, if selenium is not a good tool for this ppurpose? Commented Jul 20, 2021 at 21:03

1 Answer 1

1

I am not sure why are you using Selenium for load testing, You may wanna have a look at jmeter

Having said that, for this particular task, you can switch between tabs. You can go to any tab from any tab in Selenium.

I would assume that you have click somewhere on the first tab and then a new tab must have been opened, right ?

If that is the case, you can use the below sample code :

driver.maximize_window()
driver.implicitly_wait(30)
driver.get("Your URL here")
wait = WebDriverWait(driver, 10)
first_tab_handle = driver.current_window_handle  #Storing the current or first tab windows handle
driver.find_element_by_id('some id').click() # the moment this click take place, you would see a new tab with some other or with same content (Assuming this click triggers an event)
two_tabs_handles = driver.window_handles   # Note that, two_tabs_handles will have previous tab (first tab) as well as second tab handles. 
driver.switch_to.window(two_tabs_handles[1])  #  Note that, window_handles returns a list in python, so [0] denotes the first tab whereas [1] denotes the first tab. 

#perfrom some operation here on tab 2 (e.g click somewhere to open tab3 using selenium)

three_tabs_handles = driver.window_handles 
driver.switch_to.window(two_tabs_handles[2])

and so on... 

PS :- Read out the comments for better understanding.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.