Seite 1 von 1

Automatische googleabfrage und "Ich Stimmt" Button Probleme

Verfasst: Samstag 4. Juni 2022, 19:22
von MarionStorm
Hallo Leute ich versuche die möglichkeit das POPUP auf Ich stimme zu zu setzten aber finde leider nicht den Weg dorthin.

Kann jemadn helfen?

Code sieht so aus:

Code: Alles auswählen

from selenium import webdriver

driver = webdriver.Chrome(r'C:\Users\Admin\Desktop\Python\chromedriver.exe')
driver.get('https://www.google.de/xhtml')
time.sleep(5)
search_field = driver.find_element_by_name('q')
search_field.send_keys('google')
search_field.submit()

Re: Automatische googleabfrage und "Ich Stimmt" Button Probleme

Verfasst: Sonntag 5. Juni 2022, 17:24
von MarionStorm
Hallo habe mitlerweile das Problem durch YouTube Videos lösen können.

Der Code hierzu lautet:

Code: Alles auswählen

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time

driver = webdriver.Chrome(r'C:\Users\Admin\Desktop\Python\chromedriver.exe')
driver.get('https://google.com/xhtml')

time.sleep(2) # seconds until popup appears

try: # 2 different popups
    frame = driver.find_element_by_xpath('//*[@id="cnsw"]/iframe') #<-locating chrome cookies consent frame 
    driver.switch_to.frame(frame) 
    driver.find_element_by_xpath('//*[@id="introAgreeButton"]').click()#<-looking for introAgreeButton button, but seems google has changed its name since and  it only works in old chrome versions.

except NoSuchElementException:
    driver.find_element_by_xpath('//*[@id="L2AGLb"]').click() #<- pay attention to new id.

search_field = driver.find_element_by_name('q')
search_field.send_keys('google')
search_field.submit()
time.sleep(5)
driver.quit()