英文:
(Python, Selenium) How do I click on a radio button?
问题
以下是您要翻译的内容:
"不像听起来那么容易,至少对我来说不是。我想要爬取这个页面,我想要迭代遍历该商品的不同变体,并获取每个变体的个别数据。我制作了一个脚本,找到了我要找的单选按钮并迭代它们,但由于类名没有更改为'active',页面没有更新。
下面的代码是迭代单选元素的代码块。我认为问题在于类名没有更改为'active'。我不确定如何解决这个问题。使用这个小代码块,我能够单击按钮,它会被轮廓化。然而,它没有更改为'active',因此页面保持不变,我无法爬取页面上的任何唯一数据。
for color in driver.find_element(By.XPATH, "//div[@class='product-intro__color-radio']"):
name = color.get_attribute("aria-label")
colorPic = color.find_element(By.TAG_NAME, "img").get_attribute("src")
price = driver.find_element(By.CLASS_NAME, "from").get_attribute("aria-label")
pictures = []
for pic in (driver.find_element(By.CLASS_NAME, "product-intro__thumbs-inner").find_elements(By.CLASS_NAME, "j-verlok-lazy loaded")):
pictures.append(pic.get_attribute("src"))
try:
print(color.get_attribute("class"))
color.find_element(By.CLASS_NAME, "color-inner").click()
except:
print("no more colors")
英文:
Not as easy as it sounds, to me at least. I want to scrape this page, I want to iterate through the different variants of the item and get each ones individual data. I made a script which found the radio button I was looking for and iterates through them, but because the class name doesn't change to active, the page doesn't update.
the code below is the chunk that iterates through the radio elements. I think that the issue is that the class name doesn't change to ~active. I'm not sure how to go about this. With this little chunk of code I am able to click on the button, it becomes outlined. however it doesn't get changed to active, and so the page remains the same, and I can't scrape any of the page unique data.
for color in driver.find_element(By.XPATH, "//div[@class='product-intro__color-radio']"):
name = color.get_attribute("aria-label")
colorPic = color.find_element(By.TAG_NAME, "img").get_attribute("src")
price = driver.find_element(By.CLASS_NAME, "from").get_attribute("aria-label")
pictures = []
for pic in (driver.find_element(By.CLASS_NAME, "product-intro__thumbs-inner").find_elements(By.CLASS_NAME, "j-verlok-lazy loaded")):
pictures.append(pic.get_attribute("src"))
try:
print(color.get_attribute("class"))
color.find_element(By.CLASS_NAME, "color-inner").click()
except:
print("no more colors")
答案1
得分: 0
I tried to scrape this website using the same code that you provided, but refresh the page/and click on the radio buttons manually by opening Chrome without putting it in heedless mode. The discovery is that this website detects the automated Chrome and CloudFlare anti-spider mechanisms are triggered. Once such mechanism is triggered, you can't click on radio buttons anymore.
Hence, my suggestion is to use undetected_chromedriver
(https://pypi.org/project/undetected-chromedriver/).
And put that before your code. To address the question of how to click the radio button:
for color in driver.find_elements(
By.XPATH, "//div[@class='product-intro__color-radio']"
):
color.click()
# ... and rest of your code
Here is the complete code for reference:
from contextlib import suppress
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
url = "https://us.shein.com/Men-Playing-Card-Print-Tee-p-9847947-cat-1980.html"
driver = uc.Chrome(options=uc.ChromeOptions())
driver.get(url)
with suppress(Exception):
# pass the popup, if it exists. Not necessary
el = WebDriverWait(driver, 2).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, ".sui-dialog__body .icon-close")
)
)
el.click()
WebDriverWait(driver, 2).until_not(
EC.visibility_of_any_elements_located(
(
By.CSS_SELECTOR,
".sui-dialog__body",
)
)
)
for color in driver.find_elements(
By.XPATH, "//div[@class='product-intro__color-radio']"
):
color.click()
color_picture = color.find_element(By.TAG_NAME, "img").get_attribute("src")
price = driver.find_element(By.CLASS_NAME, "from").get_attribute("aria-label")
pictures = []
for pic in driver.find_element(
By.CLASS_NAME, "product-intro__thumbs-inner"
).find_elements(By.TAG_NAME, "img"):
pictures.append(pic.get_attribute("src"))
print("Color: ", color_picture, "Price: ", price, "Pictures: ", pictures)
driver.quit()
And that would get you something like the below:
Color: //img.ltwebstatic.com/images3_pi/2023/05/26/16850972394510b9b39d2055fae4fbd766312765b3.webp Price: $9.99
Pictures:
[
'https://img.ltwebstatic.com/images3_pi/2023/06/09/1686283252950c14a47c5620fe28b3b7f552f3aeba_thumbnail_220x293_thumbnail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/168628325393daa048a889f35edd08067049d5c7fb_thumbnail_220x293_thumbnail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/1686283255fad5c3fad15a8727a735af63049babae_thumbnail_220x293_thumbnail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/1686283256451f2e224d187cfb0cb8234776f88587_thumbnail_220x293_thumbnail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/16862832570b95b0076cc3fd29aee875cd1637dadc_thumbnail_220x293_thumbnail_160x.webp',
'//img.ltwebstatic.com/images3_pi/2023/06/09/168628326140466b1c305886b5fd96b29e9ea72dcc_thumbnail_220x293_thumbnail_160x.webp'
]
#...
英文:
I tried to scrape this website using the same code that you provided, but refresh the page/and click on the radio buttons manually by opening Chrome without putting it in heedless mode. The discovery is that this website detects the automated Chrome and CloudFlare anti-spider mechanisms are triggered. Once such mechanism is triggered, you can't click on radio buttons anymore.
Hence, my suggestion is to use undetected_chromedriver
(https://pypi.org/project/undetected-chromedriver/).
import undetected_chromedriver as UC
url = "https://us.shein.com/Men-Playing-Card-Print-Tee-p-9847947-cat-1980.html"
driver = uc.Chrome(options=uc.ChromeOptions())
driver.get(url)
And put that before your code. To address the question of how to click the radio button:
for color in driver.find_elements(
By.XPATH, "//div[@class='product-intro__color-radio']"
):
color.click()
# ... and rest of your code
Would be sufficient.
UPDATE:
Here is the complete code for reference:
from contextlib import suppress
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
url = "https://us.shein.com/Men-Playing-Card-Print-Tee-p-9847947-cat-1980.html"
driver = uc.Chrome(options=uc.ChromeOptions())
driver.get(url)
with suppress(Exception):
# pass the popup, if it exists. Not necessary
el = WebDriverWait(driver, 2).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, ".sui-dialog__body .icon-close")
)
)
el.click()
WebDriverWait(driver, 2).until_not(
EC.visibility_of_any_elements_located(
(
By.CSS_SELECTOR,
".sui-dialog__body",
)
)
)
for color in driver.find_elements(
By.XPATH, "//div[@class='product-intro__color-radio']"
):
color.click()
color_picture = color.find_element(By.TAG_NAME, "img").get_attribute("src")
price = driver.find_element(By.CLASS_NAME, "from").get_attribute("aria-label")
pictures = []
for pic in driver.find_element(
By.CLASS_NAME, "product-intro__thumbs-inner"
).find_elements(By.TAG_NAME, "img"):
pictures.append(pic.get_attribute("src"))
print("Color: ", color_picture, "Price: ", price, "Pictures: ", pictures)
driver.quit()
And that would get you something like the below:
Color: //img.ltwebstatic.com/images3_pi/2023/05/26/16850972394510b9b39d2055fae4fbd766312765b3.webp Price: $9.99
Pictures:
[
'https://img.ltwebstatic.com/images3_pi/2023/06/09/1686283252950c14a47c5620fe28b3b7f552f3aeba_thumbnail_220x293_thumb
nail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/168628325393daa048a889f35edd08067049d5c7fb_thumbnail_220x293_thumb
nail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/1686283255fad5c3fad15a8727a735af63049babae_thumbnail_220x293_thumb
nail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/1686283256451f2e224d187cfb0cb8234776f88587_thumbnail_220x293_thumb
nail_160x.webp',
'https://img.ltwebstatic.com/images3_pi/2023/06/09/16862832570b95b0076cc3fd29aee875cd1637dadc_thumbnail_220x293_thumb
nail_160x.webp',
'//img.ltwebstatic.com/images3_pi/2023/06/09/168628326140466b1c305886b5fd96b29e9ea72dcc_thumbnail_220x293_thumbnail_1
60x.webp'
]
#...
答案2
得分: 0
这是解决您问题的完整解决方案
import time
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import selenium.webdriver.support.expected_conditions as EC
options = ChromeOptions()
options.add_argument("--start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 2})
driver = Chrome(options=options)
wait = WebDriverWait(driver, 10)
url = "https://us.shein.com/Men-Playing-Card-Print-Tee-p-9847947-cat-1980.html?src_identifier=on%3DIMAGE_COMPONENT%60cn%3Dcat%60hz%3DhotZone_16%60ps%3D4_10%60jc%3DitemPicking_001121429&src_module=Women&src_tab_page_id=page_home1685728955945&mallCode=1"
driver.get(url)
# 等待关闭优惠券弹窗
coupon_box = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.c-coupon-box')))
coupon_box.find_element(By.CSS_SELECTOR, 'i.iconfont.icon-close.she-close').click()
# 等待最小化注册容器侧边栏
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.quickg-outside')))
driver.execute_script("document.querySelector('i.svgicon.svgicon-arrow-left').click();")
for color in driver.find_elements(By.CSS_SELECTOR, "div[class^='product-intro__color-radio']"):
color.click()
time.sleep(2)
name = color.get_attribute("aria-label")
colorPic = color.find_element(By.TAG_NAME, "img").get_attribute("src")
price = driver.find_element(By.CLASS_NAME, "from").get_attribute("aria-label")
pictures = []
for pic in driver.find_element(By.CLASS_NAME, "product-intro__thumbs-inner").find_elements(By.TAG_NAME, "img"):
pictures.append(pic.get_attribute("src"))
print(f"color name: {name}, color link: {colorPic}, price: {price}, pictures: {pictures}")
输出:
color name: Black, color link: //img.ltwebstatic.com/images3_pi/2021/11/19/16373006737a500b475216fa087eb27f22fd30c740.webp, price: $3.95, pictures: ['https://img.ltwebstatic.com/images3_pi/2022/03/30/1648607744201e687899d1e89300ec09df78378581_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/02/22/1645515919fda37bd39f4dfd40f533d4da9036f2ed_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/02/22/16455159225e0dfa26570a2c2e6bc86c663a7ec89a_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/02/18/16451504123a4d9cb6148747d2767d0c5ec1a3854f_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2021/11/19/16373006661a720cb1c49905c10a44417d3be5fb85_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/03/30/1648607744201e687899d1e89300ec09df78378581_thumbnail_80x.webp']
color name: White, color link: //img.ltwebstatic.com/images3_pi/2022/04/13/1649838582f18982814c717e0a48ea09575d2b6012.webp, price: $9.99, pictures: ['https://img.ltwebstatic.com/images3_pi/2022/05/06/16518168250138469f410c81b6a93479b88cd594a7_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983857235315ce2463f9f31665c01edaeaa095d_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/16498385736d70c61db04b42982558991f7bc19637_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/1649838579c81530935b31eb9adc4407f58ad39f9f_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983857463bf832df86ec2358f3f2b115befdd79_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983857235315ce2463f9f31665c01edaeaa095d_thumbnail_160x.webp']
color name: Grey, color link: //img.ltwebstatic.com/images3_pi/2023/04/19/16818684614d82376e7a984235a77558cdea072b28.webp, price: $9.99, pictures: ['https://img.ltwebstatic.com/images3_pi/2023/04/20/16819620851c0c458532cf584090a736cad6ec3a0c_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/1681868451e6772bb900015a216a2d652672a8d5e4_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/1681868453819b252a03454b4d97bfe7f997e4bd72_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/1681868456a909949c341e541c1991c2ed92963783_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/168186845868fe18db47c819889ea404ab1d14fb78
<details>
<summary>英文:</summary>
Here's the complete solution to your problem
```python
import time
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import selenium.webdriver.support.expected_conditions as EC
options = ChromeOptions()
options.add_argument("--start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 2})
driver = Chrome(options=options)
wait = WebDriverWait(driver, 10)
url = "https://us.shein.com/Men-Playing-Card-Print-Tee-p-9847947-cat-1980.html?src_identifier=on%3DIMAGE_COMPONENT%60cn%3Dcat%60hz%3DhotZone_16%60ps%3D4_10%60jc%3DitemPicking_001121429&src_module=Women&src_tab_page_id=page_home1685728955945&mallCode=1"
driver.get(url)
# wait to close the coupon-box
coupon_box = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.c-coupon-box')))
coupon_box.find_element(By.CSS_SELECTOR, 'i.iconfont.icon-close.she-close').click()
# # wait to minimize the register-container side box
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.quickg-outside')))
driver.execute_script("document.querySelector('i.svgicon.svgicon-arrow-left').click();")
for color in driver.find_elements(By.CSS_SELECTOR, "div[class^='product-intro__color-radio']"):
color.click()
time.sleep(2)
name = color.get_attribute("aria-label")
colorPic = color.find_element(By.TAG_NAME, "img").get_attribute("src")
price = driver.find_element(By.CLASS_NAME, "from").get_attribute("aria-label")
pictures = []
for pic in driver.find_element(By.CLASS_NAME, "product-intro__thumbs-inner").find_elements(By.TAG_NAME, "img"):
pictures.append(pic.get_attribute("src"))
print(f"color name: {name}, color link: {colorPic}, price: {price}, pictures: {pictures}")
output:
color name: Black, color link: //img.ltwebstatic.com/images3_pi/2021/11/19/16373006737a500b475216fa087eb27f22fd30c740.webp, price: $3.95, pictures: ['https://img.ltwebstatic.com/images3_pi/2022/03/30/1648607744201e687899d1e89300ec09df78378581_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/02/22/1645515919fda37bd39f4dfd40f533d4da9036f2ed_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/02/22/16455159225e0dfa26570a2c2e6bc86c663a7ec89a_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/02/18/16451504123a4d9cb6148747d2767d0c5ec1a3854f_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2021/11/19/16373006661a720cb1c49905c10a44417d3be5fb85_thumbnail_220x293_thumbnail_80x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/03/30/1648607744201e687899d1e89300ec09df78378581_thumbnail_80x.webp']
color name: White, color link: //img.ltwebstatic.com/images3_pi/2022/04/13/1649838582f18982814c717e0a48ea09575d2b6012.webp, price: $9.99, pictures: ['https://img.ltwebstatic.com/images3_pi/2022/05/06/16518168250138469f410c81b6a93479b88cd594a7_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983857235315ce2463f9f31665c01edaeaa095d_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/16498385736d70c61db04b42982558991f7bc19637_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/1649838579c81530935b31eb9adc4407f58ad39f9f_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983857463bf832df86ec2358f3f2b115befdd79_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983857235315ce2463f9f31665c01edaeaa095d_thumbnail_160x.webp']
color name: Grey, color link: //img.ltwebstatic.com/images3_pi/2023/04/19/16818684614d82376e7a984235a77558cdea072b28.webp, price: $9.99, pictures: ['https://img.ltwebstatic.com/images3_pi/2023/04/20/16819620851c0c458532cf584090a736cad6ec3a0c_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/1681868451e6772bb900015a216a2d652672a8d5e4_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/1681868453819b252a03454b4d97bfe7f997e4bd72_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/1681868456a909949c341e541c1991c2ed92963783_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/04/19/168186845868fe18db47c819889ea404ab1d14fb78_thumbnail_220x293_thumbnail_160x.webp']
color name: Army Green, color link: //img.ltwebstatic.com/images3_pi/2023/05/26/16850972394510b9b39d2055fae4fbd766312765b3.webp, price: $8.49, pictures: ['https://img.ltwebstatic.com/images3_pi/2023/05/26/1685097221ea6f8683e774359f9c02a864f9472945_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/26/16850972257ded2b284608a5b0ea64aabb44852e4d_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/26/16850972274a3a392fff2ff804db91184b7a3b46a5_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/26/1685097230b25258693dc0271a3b79a03f5ef583e1_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/26/1685097232afababceb537ea423001193c216c0da2_thumbnail_220x293_thumbnail_160x.webp', '//img.ltwebstatic.com/images3_pi/2023/05/26/16850972345df23f1c2d6683ced7ef50220af3b30d_thumbnail_220x293_thumbnail_160x.webp']
color name: Red, color link: //img.ltwebstatic.com/images3_pi/2023/05/16/16841952367006451215ff0ddfb4bccc8ac069cd49.webp, price: $8.49, pictures: ['https://img.ltwebstatic.com/images3_pi/2023/05/16/168422763055cee2b156fcab44de548ffb02847c91_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/16/1684195223ff0f79cfa39c20eefe8b02f1396d006e_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/16/1684195225bdcaa84483bb2b94efc71ed6b3e26c60_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/16/1684195227595f607989a0419d33e418ee31f8bee6_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2023/05/16/16841952293ffd51e2082213eca2846d6fc77eea15_thumbnail_220x293_thumbnail_160x.webp', '//img.ltwebstatic.com/images3_pi/2023/05/16/16841952324342c2899b3b3b4ec3545c931ab9170b_thumbnail_220x293_thumbnail_160x.webp']
color name: Khaki, color link: //img.ltwebstatic.com/images3_pi/2022/04/13/1649838584ad23a5fe562fba651e1111d3c033df40.webp, price: $7.99, pictures: ['https://img.ltwebstatic.com/images3_pi/2022/06/20/1655721810d04389d8458ef100b417017ac151daa1_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/16498385751552063a9533da902200fd796c36df05_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983857777be8a249864829499f1ae742e545a22_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/13/164983858021125bcd323b9bda9facf7e21578c40f_thumbnail_220x293_thumbnail_160x.webp', 'https://img.ltwebstatic.com/images3_pi/2022/04/27/1651057130a07c0aa9cd14036965189d07e35c5e41_thumbnail_220x293_thumbnail_160x.webp', '//img.ltwebstatic.com/images3_pi/2022/04/13/16498385786423ea548a5fa8bc1d0bb77d66628fe0_thumbnail_220x293_thumbnail_160x.webp', '//img.ltwebstatic.com/images3_pi/2022/04/13/16498385751552063a9533da902200fd796c36df05_thumbnail_160x.webp']
steps to follow:
-
First, as the page loads, it coupon box pops up and we need to close it to proceed. Therefore we wait for the coupon-box web element to appear and then click to close it.
-
Next, A register container appears from the right side over the web element containing the radio buttons of color options. Thus, we wait for it to appear and minimize it by clicking on the arrow.
-
Now, we simply find all the available color radio button(here 6) for the product, iterate over them one-by-one and in every iteration click on the respective color radio button to extract all the details of the product with the specific chosen color.
As you can see, it outputs the product details (color name, color pic, price of the product for the color, and all the pictures of the product available for the color).
I hope it answers your question.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论