Search code examples
python-3.xselenium-webdriverselenium-chromedriverbrowser-automation

How can bypass this issue here in redbubble


I just coded a redbubble auto upload program but while logging in everything works perfect but after some time i have tried got a problem in captcha i am anot able to slove it also i have tried cookies = driver.get_cookies() and got the cookies and printed the cookies using driver.add_cookie(cookie) . But still i am not able to login to the website also while doing manually i just got a popup in open dialgoe box how can i handle the popup.

my concept is i need to upload the file using CSV this is my concept.

I have attached the code for reference can anyone please help me.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time

path = Service(r'C:\Users\yazha\OneDrive\Pictures\New folder\chromedriver.exe')
driver = webdriver.Chrome(service=path)
driver.get('https://www.redbubble.com/')driver.find_element(By.LINK_TEXT, "Login").click()
time.sleep(10)
driver.find_element(By.ID, "ReduxFormInput1").clear()
time.sleep(4)
driver.find_element(By.ID, "ReduxFormInput1").send_keys("")
time.sleep(4)
driver.find_element(By.ID, "ReduxFormInput2").clear()

driver.find_element(By.ID, "ReduxFormInput2").send_keys("")
time.sleep(10)
driver.find_element(By.XPATH,"//*[@id='RB_React_Component_LoginFormContainer_0']/div/form/div[3]/div[1]/div/label").is_selected()
driver.find_element(By.CLASS_NAME, "app-ui-components-Button-Button_button_1_MpP").click()

cookies = driver.get_cookies()
print(cookies)
# Create a new instance of the chrome
driver = webdriver.Chrome(service=path)

# Navigate to the website
driver.get('https://www.redbubble.com/')
time.sleep(20)

for cookie in cookies:

driver.add_cookies(cookie)

driver.refresh()

Solution

  • First, you need to login in using your username/email and password as you're doing in the script above.

    Next, you should save the cookies so that next time onwards, you just need to load these cookies to directly open the website as already logged in.

    json_object = json.dumps(driver.get_cookies())
    # save the cookies in a file 
    with open("cookies.json", "w") as outfile:
        outfile.write(json_object)
    

    Next time onwards, you just need to directly go to the website, load the cookies and refresh it.

    # open then website
    driver.get("https://www.redbubble.com/")
    
    f = open('cookies.json')
    cookies = json.loads(f)
    # Load cookies to the driver
    for cookie in cookies:
        driver.add_cookie(cookie)
    
    time.sleep(2)
    
    # refresh the browser
    driver.refresh()