Issue
I am trying to get "how to use" text value from this page, see the screenshot:
I tried this css selector but I don't understand why I am not getting the text value
how_to_use = driver.find_element(By.LINK_TEXT, "How to use").click() #clicking on How to use section
how_to_use = driver.find_element(By.CSS_SELECTOR,"#qqrco4-accordion div").text #trying to get how to use section text
can anyone please help me?
Solution
I hope you are scrolling the page before clicking the line
how_to_use = driver.find_element(By.LINK_TEXT, "How to use").click()
If so, to get the text you want to get you need to improve the locator and wait for that element to be visible.
I have no time to search for better locators there, but the following code is worked
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)
url = "https://www.sephora.ae/en/p/nude-obsession-lip-kit-P10043065.html"
driver.get(url)
wait = WebDriverWait(driver, 10)
driver.execute_script("window.scrollBy(0, arguments[0]);", 600)
time.sleep(1)
wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "How to use"))).click()
time.sleep(1)
content = driver.find_element(By.CSS_SELECTOR, '.tabs-panel.is-active div').text
print(content)
The output is:
C:\Users\*****\PycharmProjects\test\venv\Scripts\python.exe C:/Users/*****/PycharmProjects/test/so.py
Step 1: Define
Artist Color Pencil:
Matte, highly pigmented, and easy glide pencil to define & correct the lip shape.
Step 2: Color
Rouge Artist:
Exquisite gliding & comfortable texture with moisturizing effect for 24 hours.
Process finished with exit code 0
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.