为什么当元素存在时硒会超时

问题描述 投票:0回答:2

我在下面有一个问题代码,其中元素变得可见但未被单击。我尝试了 css 选择器和 xpath。

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


PROXY = "socks5://184.178.172.13:15311"  # IP:PORT or HOST:PORT

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)

driver = webdriver.Chrome(chrome_options=chrome_options)

driver.get('https://nitrogensports.eu/sport/tennis/starting-soon')
wait = WebDriverWait(driver, 30)
table = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="modal-welcome-new-button"]')))
table.click()
table = wait.until(EC.presence_of_element_located((By.XPATH, '//div[class="div.events-result-set"]')))
print("finished")
time.sleep(30)
driver.close()
python selenium webdriver webdriverwait
2个回答
1
投票

根据您的问题,标识为

(By.XPATH, '//*[@id="modal-welcome-new-button"]')
的元素未被点击。

等待结束并且元素被识别并返回后,在调用

click()
方法时向前移动,因此您需要使用 presence_of_element_located
 方法,而不是使用 expected_conditions
 方法 
element_to_be_clickable
,如下所示:

driver.get('https://nitrogensports.eu/sport/tennis/starting-soon')
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='party-button highlightable-button highlighted' and @id='modal-welcome-new-button']"))).click()

0
投票

尝试切换到框架(如果有)

© www.soinside.com 2019 - 2024. All rights reserved.