我运行这段代码
#Gets to the Calendar for the week with the Login Details
calendar = driver.get('https://www.investing.com/economic-calendar/')
time.sleep(5)
driver.find_element_by_xpath('/html/body/div[9]/div[3]')
driver.find_element_by_xpath('//*[@id="onetrust-accept-btn-handler"]').click()
time.sleep(5)
driver.find_element_by_xpath('/html/body/div[10]/div')
driver.find_element_by_xpath('/html/body/div[10]/div/div[4]/button[1]').click()
有时我成功有时我会出错
ElementClickInterceptedException: element click intercepted: Element <a onclick="overlay.overlayLogin();" href="javascript:void(0);" class="login bold">...</a> is not clickable at point (821, 19). Other element would receive the click: <div class="allow-notifications-popup-wrapper shown">...</div>
(Session info: chrome=84.0.4147.135)
因为顽皮的弹出窗口/警报并不总是出现。
如何编写 IF(弹出窗口)然后单击它
或者
IF pop-不存在跳过以下两行吗?
谢谢
最佳答案
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
应该能够完全绕过弹出窗口。
关于python - Selenium 中的 IF/THEN 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63550722/