Created
September 27, 2020 15:15
-
-
Save tonetheman/9bc7388a2b468272bbc3fb3a570af963 to your computer and use it in GitHub Desktop.
find a radio button to click on
This file contains hidden or 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
URI = "https://www.16personalities.com/free-personality-test" | |
from selenium.webdriver import Chrome, ChromeOptions | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.common.by import By | |
import traceback,time | |
chrome_options = ChromeOptions() | |
chrome_options.add_argument("--incognito") | |
chrome_options.add_argument('--disable-extensions') | |
chrome_options.headless = False | |
driver = None | |
try: | |
driver = Chrome(options=chrome_options) | |
driver.get(URI) | |
print("should be done loading") | |
driver.get_screenshot_as_file("radio.png") | |
# first find the quiz chunk block | |
# prob could key on something else here... seemed good though | |
e=driver.find_element(By.XPATH, "//div[@data-chunk='quiz-chunk']") | |
# get a list of question elements | |
# this is AN ARRAY IN MY EXAMPLE I AM ONLY touching element 0 | |
q = e.find_elements(By.CLASS_NAME,"question") | |
# find the options under element 0 | |
o = q[0].find_element(By.CLASS_NAME,"options") | |
# get an options you can really click on | |
# NOTICE HERE you can use the data-index to pick any of the options | |
reals = o.find_element(By.CSS_SELECTOR,"[data-index='1']") | |
# clicky click | |
reals.click() | |
# proves it | |
driver.get_screenshot_as_file("radio_clicked.png") | |
finally: | |
if driver is not None: | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment