Python + Selenium. CSS Selector or Xpath

I would use CSS selector Here is complete example:

from selenium import webdriver
from import expected_conditions as EC
from import By
from import WebDriverWait

chrome_options = webdriver.ChromeOptions()

wd = webdriver.Chrome('<<PATH_TO_CHROMEDRIVER>>', options=chrome_options)

url = ''

# load page via selenium

# wait 5 seconds until page will be loaded
text_input = WebDriverWait(wd, 5).until(EC.presence_of_element_located((By.ID, 'text')))
text_input.send_keys('Hello world')

# wait for popup to appear
popup = WebDriverWait(wd, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, '')))

# wait for popup third child and click it
WebDriverWait(popup, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'li:nth-child(3)'))).click();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top