0

I'm working on a project and I have to go to a site and drop a soy there. I am trying to do this using the Python selenium module, but when I enter the site with a bot, I get a popup (an acceptance form about cookies). I cannot achieve what I am trying to do without pressing accept.

enter image description here

I checked the network section of the site and found the site containing cookies, when I enter that site the code works properly and it succeeds in pushing the accept cookies button, but this does not work for me because it cannot even find the accept button on the main site, I know it is not because it is written in javascript, but i don't know how to do this.

Anyway, let's get to the code part.

on the site I'm trying to login

the site that sent the cookie form the site uses

this code works for this:

from selenium import webdriver
import time
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

option = webdriver.ChromeOptions()
option.add_argument('--disable-notifications')
option.add_argument("--mute-audio")

driver = webdriver.Chrome("chromedriver.exe", options=option)


driver.get('https://consent-pref.trustarc.com/?type=jefftest_ibm&site=ibm.com&action=notice&country=tr&locale=tr&behavior=expressed&gtm=1&layout=default_eu&irm=undefined&from=https://consent.trustarc.com/#')


time.sleep(10)
driver.find_elements_by_class_name("call")[0].click()

but it doesn't work for the other, how can I get this to work for the other too?

2 Answers 2

1

You could use pyautogui instead to stimulate the click:

import pyautogui

pyautogui.click(x=100, y=200)
Sign up to request clarification or add additional context in comments.

3 Comments

my code is already working for this site, this is the site that is not working :)
After a few tries I found the correct coordinates and it worked, so I want to ask you something, is there a way to find the coordinates of the direct button without trying?
I don't think there is. You could use pyautogui.position() to get the position and use try and except commands to try and figure out where the button is, but as far as I'm aware there is no direct way to get the location of a button with pyautogui
0

@The Pilot Dude 's answer works in a way, but it can't be said to be very dynamic so:

I went to the site with original chrome and accepted cookies and saved these cookies. When I had to re-enter the site later, I reloaded the cookies.

for download cookies:

import pickle
import time
from selenium import webdriver

option = webdriver.ChromeOptions()
option.add_argument("--disable-notifications")
option.add_argument("--mute-audio")
option.add_argument("user-data-dir=C:\\Users\\___*******__\\AppData\Local\\Google\\Chrome\\User Data")
driver = webdriver.Chrome(options = option)

driver.get('https://speech-to-text-demo.ng.bluemix.net/')

time.sleep(10)#in this time I accepted cookies

pickle.dump(driver.get_cookies(), open("cookies.pkl","wb"))#for download cookies

and after that I can use cookies for chromedriver.exe

for use cookies:

import pickle
from selenium import webdriver

option = webdriver.ChromeOptions()
option.add_argument("--disable-notifications")
option.add_argument("--mute-audio")
driver = webdriver.Chrome("chromedriver.exe", options = option)

driver.get('https://speech-to-text-demo.ng.bluemix.net/')

file = open("cookies.pkl","rb")
cookies = pickle.load(file)
for cookie in cookies:
    driver.add_cookie(cookie)#for use cookies
file.close()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.