I’m working to automate web page where i’m unable to close the pop up. I have tried to refresh/switch to pop up window, nothing worked.
Code:
JavaScript
x
17
17
1
from selenium import webdriver
2
import time
3
driver = webdriver.Chrome(executable_path='F:chromedriver_win32chromedriver.exe')
4
driver.get('https://www.libertymutual.com/get-a-quote')
5
driver.maximize_window()
6
driver.find_element_by_xpath(
7
'//*[@id="1555468516747"]/section/div[2]/section/form/div[1]/div[3]/div/div[1]').click()
8
time.sleep(1)
9
driver.find_element_by_xpath('//*[@id="zipcode-1555468516747-1555468516747"]').click()
10
driver.find_element_by_xpath('//*[@id="zipcode-1555468516747-1555468516747"]').send_keys('03878')
11
time.sleep(1)
12
driver.find_element_by_xpath(
13
'//*[@id="1555468516747"]/section/div[2]/section/form/div[2]/div[5]/div/div/button').submit()
14
time.sleep(5)
15
x=driver.find_element_by_xpath('//*[@id="discount-marketing-modal"]/header/button/svg').click()
16
driver.refresh()
17
If you want directly go to web page, https://buy.libertymutual.com/auto?city=Somersworth&jurisdiction=NH&lob=Auto&policyType=Auto&zipCode=03878
Advertisement
Answer
Replace last 3 lines of your code by below lines.Used action chain to click.
JavaScript
1
5
1
time.sleep(5)
2
ok = driver.find_element_by_xpath('//*[@id="discount-marketing-modal"]/footer/button')
3
ActionChains(driver).move_to_element(ok).pause(1).click(ok).perform()
4
x=driver.find_element_by_xpath('//*[@id="discount-marketing-modal"]/header/button/svg').click()
5