Closed Ramonrune closed 8 months ago
I see several things that can be improved:
extension_dir
arg for the Driver()
manager: https://github.com/seleniumbase/SeleniumBase/blob/2036a7b9b4218daffb8a7106481134c6529ae3cc/seleniumbase/plugins/driver_manager.py#L110(Use existing args rather than passing to chromium_arg
when you can.)
headless
mode. SeleniumBase has a headless2
option to trigger the newer headless mode: https://github.com/seleniumbase/SeleniumBase/blob/2036a7b9b4218daffb8a7106481134c6529ae3cc/seleniumbase/plugins/driver_manager.py#L68(There's a Stack Overflow post about the newer headless mode here: https://stackoverflow.com/a/73840130/7058266 - which is triggered by headless2
in SeleniumBase.)
headless2
mode still has issues, use a virtual display. Since you're using the Driver()
manager, you may need to use https://github.com/mdmintz/sbVirtualDisplay for that. If you were using the SB()
manager instead, it comes with an xvfb
option for that: https://github.com/seleniumbase/SeleniumBase/blob/2036a7b9b4218daffb8a7106481134c6529ae3cc/seleniumbase/plugins/sb_manager.py#L83(The Driver()
manager doesn't have xvfb
as a direct arg.)
driver
in SeleniumBase adds more methods than found in the original Selenium driver
instance: https://github.com/seleniumbase/SeleniumBase/issues/2200#issue-1952880367You shouldn't have to use EC.presence_of_element_located
or any of the WebDriverWait
syntax at all.
Use the built-in click methods for clicking:
driver.click(selector)
driver.js_click(selector)
driver.uc_click(selector)
(And especially since you're using UC Mode, you'll may need to use one of those to click without getting stuck.)
Thanks! I will test these approaches
Hi again!
Did the changes, but still not working, here is the new code:
args += " --shm-size=2g,"
args += " --privileged,"
args += " --verbose,"
chromium_arg = '--auto-select-certificate-for-urls={"pattern":"*","filter":{}}' + args
print(chromium_arg)
display = Display(visible=0, size=(1440, 1880))
display.start()
with SB(
uc=True,
headless2=True,
browser="chrome",
chromium_arg=chromium_arg,
extension_dir=os.path.join(os.getcwd(), 'nocaptchaai_chrome'),
xvfb=display
) as driver:
driver.get("https://login.esocial.gov.br/login.aspx")
driver.click(".sign-in")
driver.click("#login-certificate") # Stucks here
It stops in this screen. But when running on my local computer, it runs with no problem.
Here is my container:
FROM debian:bullseye-slim
ENV USER=root
ENV DISPLAY :1
RUN apt-get update && apt-get install -y --no-install-recommends \
libterm-readkey-perl ca-certificates wget expect iproute2 iputils-ping curl procps libnm0
RUN apt-get update && apt-get install -y \
fonts-liberation \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatspi2.0-0 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libdrm2 \
libexpat1 \
libgbm1 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libu2f-udev \
libvulkan1 \
libx11-6 \
libxcb1 \
libxcomposite1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
xdg-utils \
vim
# Install Chrome
RUN wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}-1_amd64.deb \
&& apt-get install -y /tmp/chrome.deb \
&& rm /tmp/chrome.deb
# Update the package repository and install necessary packages
RUN apt-get update && apt-get install -y \
python3 \
python3-pip
RUN apt-get install libnss3-tools -y
RUN apt-get install xvfb -y
ENV DISPLAY=:99
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null
RUN mkdir -p $HOME/.pki/nssdb
RUN mkdir -p $HOME/etc/opt/chrome/policies/managed
COPY policies.json $HOME/etc/opt/chrome/policies/managed/policies.json
RUN mkdir -p /etc/opt/chrome/policies/managed
COPY policies.json /etc/opt/chrome/policies/managed/policies.json
RUN pip install requests
COPY entrypoint.sh /tmp/entrypoint.sh
COPY expressvpn-activate.sh /tmp/expressvpn-activate.sh
COPY drtv.pfx /drtv.pfx
RUN pip install --requirement /tmp/requirements.txt
COPY main.py /main.py
CMD xvfb-run --server-args="-screen 0 1024x768x24" python3 main.py
@mdmintz Any ideas?
Looks more like a Dockerfile config issue than a SeleniumBase one since it's working in your other environment. I don't have any more suggestions to offer other than the ones I already provided.
Hi @mdmintz , i found the problem!
If anyone has this problem, i solved it in this way:
On the last line of docker:
RUN apt-get install -y libnss3-tools wget xvfb x11vnc fluxbox
These two lines will be used for remote connection and debugging.
RUN mkdir ~/.vnc
RUN x11vnc -storepasswd 123456 ~/.vnc/passwd # Replace 123456 with your desired VNC password
Here is the trick
CMD ["sh", "-c", "Xvfb :0 -screen 0 1024x768x16 & fluxbox & x11vnc -forever -usepw -create & python main.py"]
Xvfb: Display server
fluxbox: Windows manager
x11vnc: remote access
On main,py:
from sbvirtualdisplay import Display
display = Display(visible=0, size=(1440, 1880))
display.start()
with SB(uc=True,
headless=False,
browser="chrome",
chromium_arg=chromium_arg,
xvfb=display) as driver:
Best regards,
Hi!
I'am using selenium base to bypass one site. It works really well on my PC and on EC2/Virtual box. I'am creating a docker container for it, but when i run the code inside a container, it stucks in certificate selection part.
Here is a simple code:
Here is my dockerfile:
In the final part, there is a captcha too, which i use another solution to break (not on the above code). Notice that policies.json is the following: { "AutoSelectCertificateForUrls": ["{\"pattern\":\"*\",\"filter\":{}}"] }
Any ideas about what is could be? Code runs easily on my pc, but in container it is stucked.