在單擊提交按鈕并獲取結果頁面后,我試圖讓 selenium 單擊此站點的下一頁按鈕:https ://elibrary.ferc.gov/eLibrary/search
我已經嘗試了無數方法讓 selenium 點擊這個按鈕。結果頁面上的下一頁按鈕的html代碼在這里:
<button class="mat-paginator-navigation-next mat-icon-button" mat-icon-button="" type="button" aria-describedby="cdk-describedby-message-8" cdk-describedby-host="" aria-label="Next page" style="touch-action: none; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"><span class="mat-button-wrapper"><svg class="mat-paginator-icon" focusable="false" viewBox="0 0 24 24"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></span><div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div><div class="mat-button-focus-overlay"></div></button>
我嘗試了以下方法:
link = driver.find_element_by_xpath('//*[@id="rsltToolbar"]/mat-paginator/div/div/div[2]/button[2]')
link.click()
但是代碼不起作用。希望這是需要單擊的按鈕!我已經嘗試過 css 選擇器、class_name、javascript 等,但無濟于事。非常感謝任何幫助。
uj5u.com熱心網友回復:
link = driver.find_element_by_classname("mat-paginator-navigation-next")
應該可以正常作業
# (tested in js console with)
document.querySelector(".mat-paginator-navigation-next").click()
你可能只需要添加一個延遲(即它最初可能無法點擊(或者點擊它太快什么都不做))我認為你可以等待它以某種方式被點擊
uj5u.com熱心網友回復:
driver.findElement(By.id("submit")).click();
Thread.sleep(4000);
driver.findElement(By.xpath("//*[@id='rsltToolbar']/mat-paginator/div/div/div[2]/button[2]")).click();
您嘗試過的 XPath 作業只需要在您單擊頁面“https://elibrary.ferc.gov/eLibrary/search”上的“搜索”后添加延遲
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/425783.html
