I'm making a testsuite in Selenium Webdriver using PageObjects, but I'm in doubt wether a WebElement referenced instance can be worked even if driver points to a different frame? The site I'm writing tests for has a lot of frames (and no I can't stop using frames :-)) and one frame element on every site is a topbar. I would like to make a single PageObject for that frame that i can initialize and use from the other PageObjects that contain it.

BUT I'm in doubt wether you can used WebElements when the driver have moved on to another frame.

Example:

  1. Make and initialize new HomePage PageObject
  2. SwitchTo(frame1). SwitchTo(frame2)
  3. From the constructor make a TopBar object that initialize/instantiate the elements using driver location above. I now have a reference to a WebElement in that PageObject/frame called elmTopBar
  4. In HomePage the driver switches away from that frame (back to frame0) do do some other work

  5. Will my "old" reference to elmTopBar still be workable from this driver location (same driver object) or will i only work when driver is pointed to the frame2 everytime (meaning I have to switchTo + initialize a TopBar object everytime the HomePage needs something in the TopBar)?

I know that if I do a element search from a different frame it will not find the objects in other frame, but my question is when you make/save a reference to a WebElement does it remain workable "forever" even after doing switchTo(frameX) with the driver.

Thx in advance!

有帮助吗?

解决方案

No. You will have to 'refind' the object each time. Selenium will probably complain that the object is no longer in the cache or attached to the DOM.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top