driver.execute_script()
Run JavaScript commands.
driver.execute_script("arguments[0].scrollIntoView(true);, element)
element will be scrolled to the top of the page.
header may cover the element when you scroll to the element.
location = element.location_once_scrolled_into_view
driver.switch_to.frame("")
Switch to frame by ID, name, or numbers.
driver.switch_to.default_content()
Switch back to parent frame.
driver.switch_to.alert
Switch to Alert.
alert.accept()
alert.dismiss()
Accept/Dismiss
from selenium.driver import ActionChains
actions = ActionChains(driver)
actions.move_to_element(element).perform()
.perform() are required.
actions = ActionChains(driver)
actions.drag_and_drop(fromElement, toElement).perform()
actions.click_and_hold(fromElement).move_to_element(toElement).release().perform()
actions = ActionChains(driver)
actions.drag_and_drop_by_offset(element, 100, 0).perfrom()
Logging:
import logging
logging.info("info message")
logging.warning("warning message")
logging.error("error message")
logging.basicConfig(filename="test.log", level=logging.DEBUG)
# everything has level equal to/greater than debug will be logged.
# everything logging message follows this setting will be logged into the file.
logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s', level=logging.DEBUG) # add time and change format of messages.