2

I'm trying to click "Add to Bag" button and with selenium it work's just fine, but after using selenium-wire with authentisized proxy server, although i can still get to site and click every other button and it works, after clicking this one nothing happens. I tried multiple proxies and even tested them using external software and checked my ip on https://www.whatismyip.com/.
I also tested the proxy manualy by adding it to firefox, navigating to page and clicking the same button and it worked. I'm working on this issue a second day and I don't know what I'm supposed to find and yes using authentisized proxies is a must.

The modules and the definion of proxies:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from seleniumwire import webdriver as web

options = {
    'proxy': {
        'http': 'http://user:pass@IP:Port',
        'https': 'https://user:pass@IP:Port',
        'no_proxy': 'localhost,127.0.0.1'
    }
}

driver = web.ChromeDriver(seleniumwire_options=options)
wait = WebDriverWait(driver, c_default_wait)

Here is the code for clicking the button:

try:
    #This actually finds the button (i do some staff on this page and it is loaded and clickible)
    buy_button = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div/div[3]/div[3]/div[2]/div/div/form/div[2]/button[1]") 
    print(buy_button.text)
except:
    driver.close()

while inbag == 0:
        try:
            checkout_button = wait.until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[1]/div[2]/div/div/div[4]/div/div/div/div/div/div/div/div/div/div[3]/div/button[2]")))
        except:
            buy_button.click()
        else:
            print(checkout_button.text)
            checkout_button.click()
            inbag = 1

And here is the bash output which repeats itself:

Traceback (most recent call last):
  File "%Repo_path%\env\lib\site-packages\seleniumwire\proxy\proxy2.py", line 91, in proxy_request
    conn.request(self.command, path, req_body, dict(req.headers))
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1262, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1308, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1257, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1028, in _send_output
    self.send(msg)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 968, in send
    self.connect()
  File "D:\Repos\BOOTS-BOT\env\lib\site-packages\seleniumwire\proxy\proxy2.py", line 368, in connect
    super().connect()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1424, in connect
    super().connect()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 944, in connect
    self._tunnel()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 918, in _tunnel
    (version, code, message) = response._read_status()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 267, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out
Error making request

Update:
We found, that the problem lies in CORS POLICY, which we fixed as follows:

  • We changed to Chrome (already rewritten above)
chrome_options.add_argument("--disable-web-security")

But unfortunately few steps further we encountered simular problem with loging in, where the browser reports Error: 400 Bad request and Error: 403 Forbiden Access

SrarinCZ
  • 21
  • 2

0 Answers0