-
Notifications
You must be signed in to change notification settings - Fork 1.4k
If the window closes too quickly, switch_to_window is invalid #1435
-
If the window closes too quickly, switch_to_window is invalid
I have to wait a few seconds
I can't predict how long I will have to wait for my next step, so can there be a waiting period like timeout
self.click("close", timeout=10, delay=1)
self.sleep(3)
self.switch_to_window(-1)
Beta Was this translation helpful? Give feedback.
All reactions
You might be able to close the active window/tab directly, and then switch to the most recent one after that:
self.driver.close() self.switch_to_window(-1)
Replies: 1 comment 3 replies
-
You might be able to close the active window/tab directly, and then switch to the most recent one after that:
self.driver.close() self.switch_to_window(-1)
Beta Was this translation helpful? Give feedback.
All reactions
-
On second thought, my idea is impractical, but my business logic is to open a new page and select a portion of the content, which requires interaction with the original page through the close button on the new page, and closing it directly doesn't work
Beta Was this translation helpful? Give feedback.
All reactions
-
I can't guess what to wait for (or how long) without knowing more information. You'll have to figure that out on your own.
Beta Was this translation helpful? Give feedback.
All reactions
-
@mdmintz I wrote a use case using the demo page
from seleniumbase import BaseCase
class MyTestClass(BaseCase):
def test_demo(self):
self.open("https://seleniumbase.io/realworld/login")
self.click("//h6[@align='center']//a")
# Here's an example: After I've finished registering from here, I need to click the close button on a page
# that says "You have successfully registered."
self.click("//button[@class='close']") # Suppose there is a close button on the page
# If I just use `switch_to_window`
self.switch_to_window(-1)
# The following lookup action takes place in https://seleniumbase.io/realworld/signup
self.find_element("//h4[@class='auth-header']//font//font")
Like this:
from seleniumbase import BaseCase
class MyTestClass(BaseCase):
def test_demo(self):
self.open("https://seleniumbase.io/realworld/login")
self.click("//h6[@align='center']//a")
# Here's an example: After I've finished registering from here, I need to click the close button on a page
self.driver.close()
# If I just use `switch_to_window`
self.switch_to_window(-1)
# The following lookup action takes place in https://seleniumbase.io/realworld/signup
self.find_element("//h4[@class='auth-header']//font//font")
Beta Was this translation helpful? Give feedback.