select button based on onclick event
send ctrl + a
#main.pyimport os
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
os.environ['PATH'] += r"C:/Users/zchen/PycharmProjects/selenium"
driver = webdriver.Chrome()
driver.get("https://www.w3schools.com/html/html_scripts.asp")
driver.implicitly_wait(30)
Button = driver.find_element(By.XPATH, "//button[contains(@onclick,'demo')]")
Button.click()
Date = driver.find_element(By.ID, "demo")
print(Date.text)
Body = driver.find_element(By.TAG_NAME, "body")
Body.send_keys(Keys.CONTROL, 'a')
Body.send_keys(Keys.CONTROL, 'c')
------------------
#logs
Fri Nov 05 2021 14:10:08 GMT-0600 (Mountain Daylight Time)
reference:
select by onclick
send key combination
No comments:
Post a Comment