[英]2 download click button with same class using selenium python
我無法單擊具有相同按鈕 class 的 2 個下載按鈕。 下面是代碼
file=driver.find_element_by_xpath("(//button[@class='MuiButtonBase-root MuiIconButton-root IconButton-sc-iv40hv-1 cLszZl IconButton-sc-iv40hv-0 hbJxSM DownloadButton-sc-19l7ggt-0 gHtfyl MuiIconButton-colorPrimary'])")
driver.execute_script("arguments[0].click();", file)
這僅適用於第一個按鈕..
第二個按鈕,如果添加索引 val 2 的第二個文件...只有第二個按鈕有效
我需要一個接一個地點擊兩個下載按鈕..
要獲得特定按鈕,請嘗試使用 class 和索引,或者嘗試使用您喜歡的文本和索引。
示例您有 2 個這樣的按鈕
按鈕 1:
<button class="expedition_button awesome-button " onclick="attack(null, '2', 1, 0, '')">Attack</button>
按鈕 2:
<button class="expedition_button awesome-button " onclick="attack(null, '2', 2, 0, '')">Attack</button>
你可以完成這個
driver.find_element_by_xpath("(//button[text()[contains(.,'Attack')]])[indexval]")
driver.find_element_by_xpath("(//button[@class='expedition_button awesome-button '])[indexval]")
然后類似按鈕 2、3 和 4 只是增加索引值。
對於按鈕 1:
driver.find_element_by_xpath("(//button[text()[contains(.,'Attack')]])[1]")
或者
driver.find_element_by_xpath("(//button[@class='expedition_button awesome-button '])[1]")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.