Classwork 8
WebDriverWait() and expected_conditions in Python selenium
Setup
Below is to set up the web scrapping environment with Python selenium:
import pandas as pd
import numpy as np
import os, time, random
from io import StringIO
# Import the necessary modules from the Selenium library
from selenium import webdriver # Main module to control the browser
from selenium.webdriver.common.by import By # Helps locate elements on the webpage
from selenium.webdriver.chrome.options import Options # Allows setting browser options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import StaleElementReferenceException
# Set the working directory path
wd_path = 'ABSOLUTE_PATHNAME_OF_YOUR_WORKING_DIRECTORY' # e.g., '/Users/bchoe/Documents/DANL-210'
os.chdir(wd_path) # Change the current working directory to wd_path
os.getcwd() # Retrieve and return the current working directory
# Create an instance of Chrome options
options = Options()
# Initialize the Chrome WebDriver with the specified options
driver = webdriver.Chrome(options=options)Goal
- Use selenium to get to https://qavbox.github.io/demo/delay/.
- Use selenium to click the button with βClick me!β
- Use selenium to locate the text element that will be displayed after 5 seconds using
WebDriverWaitwithEC.presence_of_element_located.
- Its XPath is
'//*[@id="two"]'
Answer:
Discussion
Welcome to our Classwork 8 Discussion Board! π
This space is designed for you to engage with your classmates about the material covered in Classwork 8.
Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.
If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 8 materials or need clarification on any points, donβt hesitate to ask here.
All comments will be stored here.
Letβs collaborate and learn from each other!