Skip to content

Closing the page with a button throws an exception #1442

@chenqinggang001

Description

@chenqinggang001

I wrote two demo pages,You can try this locally

Page A:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Page A</title>
</head>
<body>
    <form>
        <input type="button" value="login" onclick="change()">
    </form>
<script>
    function change(){
        window.open("Page B.html");
    }
</script>
</body>
</html>

Page B:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Page B</title>
</head>
<body>
    <form>
        <input type="button" value="close" onclick="change()">
    </form>

    <script>
        function change(){
            window.close();
        }
    </script>
</body>
</html>

Normally, after clicking the button to close the page, we use self.switch_to_window(-1) to go back to the original page, but it throws an exception before it gets that far

testcae:

from seleniumbase import BaseCase

class DemoTestCase(BaseCase):

    def test_demo(self):
        self.open("file:///D:/from/your/path/Page A.html")
        self.sleep(2)
        self.click("//input[@value='login']")
        self.sleep(2)
        self.click("//input[@value='close']") # The error occurs on this line
        self.sleep(2)
        self.switch_to_window(-1)
        self.click("//button[@value='login']")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUh oh... Something needs to be fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions