SoFunction
Updated on 2024-11-12

python automation test selenium core technology waiting conditions tutorial

Mouse and keyboard events in Selenium are encapsulated in the ActionChains class, using the methods:

ActionChains(driver).click(btn).perform()

Commonly used methods in ActionChains:

Example website:/demo

Sample Scenario: OpenSahi Testspage, click the "Alert Test" page, mouse click the "Click For Alert" button in the page, the warning alert box will pop up, determine whether there is an alert on the page, if there is, then switch to the warning box, and get the warning If so, switch to the alert box and get the text message of the alert, and then click the OK button in the alert box.

Sample Script:

from selenium import webdriver
from time import sleep
from  import WebDriverWait
from  import expected_conditions as ec  
class TestWaitCondition(object):
    def setup(self):
         = ()
        ("/demo/")
 
    def test_waitcondition(self):
        #Alert Test on the dot page
        .find_element_by_xpath("/html/body/table/tbody/tr/td[3]/a[1]").click()
        #Click on the "Click For Alert" button on the page.
        .find_element_by_name("b1").click()
 
        wait = WebDriverWait(,2)
        #Wait and determine if the warning box exists
        (ec.alert_is_present())
        # Switch to the alert page
        alert = .switch_to.alert
        # Get and print the text in the warning box
        print()
        # Tap OK in the warning box that pops up
        ()
        ()

Run results:

Above: from the Geek Time course: selenium automated testing learning summary.

Above is the python automation test selenium core technology waiting condition tutorial details, more information about selenium waiting condition teach please pay attention to my other related articles!