First off – no experience with Python, Sublime Text or Selenium – please be kind..
I am having an issue building a scraper in Python – using Sublime text, Selenium and Chrome. I have updated to the latest Python, Pip and downloaded the correct Chrome Driver. The webpage pops up fine, but get errors.
JavaScript
x
11
11
1
from selenium import webdriver
2
from selenium.webdriver.chrome.service import Service
3
from selenium.webdriver.common.keys import Keys
4
from selenium.webdriver.common.by import By
5
#from selenium.webdriver.common.ui import WebDriverWait - commented out due to error
6
#from selenium.webdriver.common import expected_conditions as EC - commented out due to error
7
import time
8
driver = webdriver.Chrome("C:Program Files (x86)chromedriver.exe")
9
driver.get ("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
10
print(driver.find_element(by=By.CLASS_NAME, value='ng-tns-c210-4 text-promo-1').text)***
11
Advertisement
Answer
JavaScript
1
5
1
wait = WebDriverWait(driver, 20)
2
driver.get("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
3
elem=wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.ng-tns-c210-4.text-promo-1')))
4
print(elem.text)
5
Your class name is actually multiple class names so using css selector.
Outputs:
JavaScript
1
2
1
$80.99
2
Imports:
JavaScript
1
4
1
from selenium.webdriver.common.by import By
2
from selenium.webdriver.support.ui import WebDriverWait
3
from selenium.webdriver.support import expected_conditions as EC
4