The simplest reason is that if today you're calling myButton.click() and you're using Selenium's click() method in a hundred different places in scripts and libraries, what if you want to change the behavior of click()? Why would anyone ever want to do that? There are a few different reasons including waiting before clicking, retrying after a failed click, or my favorite: logging.
Maybe you want to go into debug mode and log every click. If you're using Selenium's click() method, you may be out of luck. If you're using your own click method, which previously did nothing but call Selenium's click(), just add a logging line:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Selenium import webdriver | |
class SelUtil | |
driver = webdriver.chrome() | |
log = someLogger | |
def click_by_xpath(xpath): | |
log.debug("About to click with xpath=" + xpath) | |
driver.find_element_by_xpath(xpath).click() |
No comments:
Post a Comment