Skip to content

Instantly share code, notes, and snippets.

@tomgross
Last active May 9, 2022 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomgross/d12987572a7ffd56b056d14b36431987 to your computer and use it in GitHub Desktop.
Save tomgross/d12987572a7ffd56b056d14b36431987 to your computer and use it in GitHub Desktop.

Welcher Selemium Selektor findet das 2. div?

    <div class="hidden" id="foo">
        Ich bin unsichtbar.
    </div>

    <div id="foo">
        Hallo Robot
    </div>

Lösung: xpath=//div[@id="foo"][2] oder besser xpath=//div[@id="foo" and contains(text(), "Robot")]

Was passiert und wie kann ich das gewünschte Verhalten erreichen?

<!-- Modal HTML embedded directly into document -->
    <div id="ex1" class="modal">
        <p>Thanks for clicking. That felt good.</p>
        <a href="#" rel="modal:close">Close</a>
    </div>

    <!-- Link to open the modal -->
    <p><a href="#ex1" rel="modal:open">Open Modal</a></p>

    <button type="button" id="clickme">Click me!</button>

Test Overlay Element | FAIL | WebDriverException: Message: unknown error: Element ... is not clickable at point (43, 123). Other element would receive the click:

...
(Session info: chrome=62.0.3202.94) (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.15063 x86_64)

Lösung: Modal schliessen, und Button clicken

Wie kann ich das Element mit dem Selektor css=#info .msg clicken?

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Delay Test</title>
    <style>
    </style>
    <script src="../dist/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">

        function delayedInsert() {
            $('#info').append("<span class='msg'>Hallo Robot</span>")
        }

        $(document).ready(function () {
            $('input[type="button"]').bind({
                click: function () {
                    window.setTimeout(delayedInsert, 6000);
                }
            })
        });

    </script>
</head>
<body>
    <h1>Delay Test</h1>

    <input type="button" value="Sag Hallo ..." name="hallo"  />
    <div id="info"></div>

</body>
</html>
  • Lösung 1: Sleep 6
  • Lösung 2: Set Selenium Timeout 10
  • Lösung 3 (die beste): Wait Until Element is Visible css=.msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment