'Getting different Ads pop up in selenium webdriver
selenium webdriver#
i am running this code on selenium webdriver(chromedriver), but the moment , it click add new customer , advertisment popup comes and i am not able to close it- not able to move forward from here. sometime ads has close and sometime ad has cancel button. can someone help me. waiting for
Answer
driver.get("https://demo.guru99.com/");
driver.findElement(By.name("emailid")).sendKeys("[email protected]");
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`
Solution 1:[1]
You can install Adblock automatically with Selenium. I wrote you an example to solve your problem. It then should never pop up an ad anymore. Here is my solution:
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
