我正在嘗試通過 python 中的 selenium 訪問并單擊“X”按鈕,以便能夠重定向到下一頁并從中加載一些信息。但是,我很難找到該元素,不知道是因為在類中還是其他原因。你們能幫我實際點擊按鈕嗎?下面的代碼是我目前擁有的。先感謝您:from selenium.webdriver import Firefoxfrom selenium.webdriver.firefox.options import Optionsimport timefrom selenium import webdriverdriver = webdriver.Firefox()url = 'https://shop.axs.co.uk/Lw%2fYCwAAAAA6dpvSAAAAAABB%2fv%2f%2f%2fwD%2f%2f%2f%2f%2fBXRoZW8yAP%2f%2f%2f%2f%2f%2f%2f%2f%2f%2f'opts = Options()browser = Firefox(options=opts)browser.get(url)#wait for all elements to loadtime.sleep(5)#working lines are commented out#search_form = browser.find_element_by_class_name("modal-open")browser.find_element_by_class_name('btn-close-svg pull-right').click()
1 回答

一只斗牛犬
TA貢獻1784條經驗 獲得超2個贊
刪除此行 -
opts = Options()
browser = Firefox(options=opts)
在這里使用 xpath-
driver.find_element_by_xpath(".//div[@class='btn-close-svg pull-right']").click()
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消