gpt4 book ai didi

javascript - Python Selenium : How to navigate Javascript based navigation

转载 作者:行者123 更新时间:2023-12-03 04:48:34 25 4
gpt4 key购买 nike

所以有问题的页面是 here ,我想导航具有以下标记的分页:

 <li class="btn-next">
<a href="javascript:ctrl.set_pageReload(2)">Suivant</a></li>

如果你注意到的话,这里正在调用 JS 方法。到目前为止我已经做到了:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = None
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 30)


def fetch(url):
driver.get(
'http://www.leparking.fr/voiture-occasion/Porsche--targa-g.html#!/voiture-occasion/Porsche--targa-g.html%3Fslider_millesime%3D1940%7C1985')

elem_more = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Suivant")))
elem_more.click()


fetch(None)

它确实将鼠标悬停在元素上,但不会在单击时导航。我该怎么办?

谢谢

最佳答案

我使用execute_script方法整理出来:

elem_more = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Suivant")))
driver.execute_script("arguments[0].click();", elem_more)

关于javascript - Python Selenium : How to navigate Javascript based navigation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42760767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com