硒网络驱动程序#
我在selenium网络驱动程序(chromedriver(上运行这段代码,但现在,它点击添加新客户,弹出广告,我无法关闭它-无法从这里继续前进。有时广告已经关闭,有时广告有取消按钮。有人能帮我吗?正在等
回答
driver.get("https://demo.guru99.com/");
driver.findElement(By.name("emailid")).sendKeys("ajay@yahoo.com");
driver.findElement(By.name("btnLogin")).click();
driver.get("https://demo.guru99.com/V4/");
driver.findElement(By.name("uid")).sendKeys("mngr385415");
driver.findElement(By.name("password")).sendKeys("regatAm");
driver.findElement(By.name("btnLogin")).click();
driver.manage().window().maximize();
driver.findElement(By.linkText("New Customer")).click();
Thread.sleep(5000);
driver.switchTo().alert().sendKeys("Close");`enter code here`
您可以使用Selenium自动安装Adblock。我给你写了一个例子来解决你的问题。这样它就不应该再弹出广告了。这是我的解决方案:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome(executable_path=r"chromedriver.exe")
wait = WebDriverWait(driver, 10)
def adblock():
driver.get(
"https://chrome.google.com/webstore/detail/adblock-%E2%80%94-best-ad-blocker/gighmmpiobklfepjocnamgkkbiglidom?hl=de")
WebDriverWait(driver, 15).until(
EC.visibility_of_all_elements_located(
(By.CLASS_NAME, "dd-Va g-c-wb g-eg-ua-Uc-c-za g-c-Oc-td-jb-oa g-c"))).click()
alert = driver.switch_to_alert()
alert.accept()
adblock()
def main():
# Your code