簡體   English   中英

如何使用 Selenium 和 Python 搜索以下行? 我試圖找到並單擊這個代表鞋子尺寸的特定按鈕

[英]How can I search the following line using Selenium with Python? Im trying to find and click this specific button that represents the size of a shoe

<button type="button" class="size-grid-dropdown size-grid-button" data-qa="size-dropdown">M 12 / W 13.5</button>

以下是我目前擁有的腳本的 Python 片段。

import time
import selenium import webdriver

url = 'some url'

driver = webdriver.Firefox()
driver.get(url)

time.sleep(1)

driver.find_element_by_link_text('M 12 / 13.5').click()

我的 output 如下:

Unable to locate element: M 12 / W 13.5

任何幫助將不勝感激!

使用xpath如下圖:雙引號加黑斜線

driver.find_element_by_xpath("//button[contains(@text,\"M 12 / 13.5\")]"));

嘗試這個,

list_items = driver.find_elements_by_tag_name("button")

search_ = "M 12 / 13.5"
for item in list_items:
    if search_ in item.text:
        item.click()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM