• notice
  • Congratulations on the launch of the Sought Tech site

Unable to click button using PythonSelenium on a certain website

I've been trying to click buttons on websites to close popups (specifically Google Vignette).I would say I am a beginner.If you want to view the html, follow the steps below.

This is the site: https : //www.finscreener.org/earnings/earnings-reported?o=1001&pg=1

But you must click at bottom index"Last Button" because Google Vignette only pops up when you try to exit the current site.

If you want to check it, then maximize the viewport, right click somewhere outside the popup viewport.If not, the popup will disappear and you cannot check.

Anyway, when Google ads show up, I want to turn them off.I tried the code below to change the iframe to an ad,

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'ad_iframe ')))
iframe=driver.find_element(By.XPATH,"//iframe[@name='ad_iframe']")
driver.switch_to.frame(iframe)

But the code cannot find the iframe and gives me a TimeoutException on the WebDriverWait line.

I tried the following but the code absolutely refuses to target the ad iframe.

  1. Change to implicit timing
  2. Try XPath and name
  • There is a link to an iframe html image at the bottom After finding the iframe, I have the following click command-which I cannot now implement.
close_button=driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[2]/div/div/div[2]/div/div/div[3]").click()

How do I find the iframe and switch to it?

uj5u.com enthusiastic netizens replied:

you have aiframeInner another.You have to switch both frames to get to the close button.

Solution 1: Turn off ads

with webdriver.Chrome() as driver:
    driver.get(url)
    wait=WebDriverWait(driver, 10)
    # Wait until the frame appears and switch to it
    wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'aswift_5')))
    driver.switch_to.frame('ad_iframe')
    driver.find_element(By.ID, 'dismiss-button').click()

You must also include the following imports:

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

Solution 2: Redraw the page

In your case this might be an easier solution, by redrawing the page, It also "closes" the popup.

driver.refresh()

Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+