hallopeterswelt
hallopeterswelt

Reputation: 53

Accept Google Cookies

I want to use Python's Selenium to accept the cookies of Google. But the ids and everything are at random values. So, how do I do for example

driver.find_element(By.XPATH, '//*[@id="L2AGLb"]').click()

?

enter image description here

Upvotes: 0

Views: 104

Answers (1)

x0xRumbleLorex0x
x0xRumbleLorex0x

Reputation: 121

You can click a particular location in x,y (that is if x,y, is known), but in your case x & y will a be constant unless you are resizing windows.

driver = webdriver.Firefox()
driver.get("http://www.google.com")
el=driver.find_elements_by_xpath("//button[contains(string(), 'Lucky')]")[0]

action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(el, 5, 5)

use this line from a id that doesnt change within the page

action.click()
action.perform()

You wouldn't have a problem if the click is offset with respect to an element that doesn't alter its ID.

Upvotes: 1

Related Questions