Advertisement
shawon_majid

selenium

Feb 3rd, 2024
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.support import expected_conditions as EC
  5. from selenium.webdriver.common.action_chains import ActionChains
  6. from selenium.webdriver.common.keys import Keys
  7. import time
  8.  
  9. options = webdriver.ChromeOptions()
  10. options.add_experimental_option("detach", True)
  11.  
  12. driver = webdriver.Chrome(options=options)
  13. actions = ActionChains(driver)
  14.  
  15. driver.get("https://monkeytype.com/")
  16.  
  17. # wait until the website is loaded
  18. wait = WebDriverWait(driver, 10)
  19.  
  20. accept_btn = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="cookiePopup"]/div[2]/div[2]/button[1]')))
  21. accept_btn.click()
  22.  
  23. words = wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="words"]')))
  24.  
  25. wordslist = []
  26.  
  27. for word in words.text.split(" "):
  28.     wordslist.append(word)
  29.  
  30.  
  31. print(wordslist)
  32. wordslist[0] = wordslist[0].replace('\n', ' ')
  33.  
  34. for word in wordslist:
  35.     actions.send_keys(word + " ").perform()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement