headless_ie_selenium not working with python - python

I'm trying to change my code to use an IE headless browser. The automation I'm doing is in a website that only works in internet explorer
My code was working great until I tried to use a headless browser
When I run this code, absolutely nothing happens, no error is thrown
# selenium 4
from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.microsoft import IEDriverManager
from selenium.webdriver.ie.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import StaleElementReferenceException
from dotenv import load_dotenv
# Inicialização do Selenium
ie_options = Options()
ie_options.ignore_zoom_level = True
## WORKS!
# driver = webdriver.Ie(service=Service(IEDriverManager().install()), options=ie_options)
## NOT WORKING
service = Service(executable_path=constantes.PATH_HEADLESS)
driver = webdriver.Ie(service=service, options=ie_options)
# Acessa a página
driver.get(constantes.URL)

I believe the reason why it seems nothing is happening is because you have no output (not printing anything). I'm not familiar with your process, but I tried it out with mine also using chrome and it worked fine. Context:
chrome_options = Options()
chrome_options.add_argument("--headless")
driver=webdriver.Chrome(service=Service('*executable
path'),options=chrome_options)
driver.get('https://stackoverflow.com/')
print(driver.title)

Related

When I start my program (Selenium) it opens web page then it closes immediately after whithout error in log

My code is very short. When I try it, the program opens web page but program closes immediately after.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
driver = webdriver.Chrome()
driver.get("https://google.com")
I believe the problem is coming from my environment, so I have not tried any changes to the code to resolve this.
You have to add the below chrome options:
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
driver.get("https://google.com")

Why does setting Edge profile results in an error in Selenium Python

I am trying to run Whatsapp web without scanning QR code every time, thus I passed a profile of Edge so that it automatically detects the previous session without asking to scan it again.
Here's my code:
import cv2
from selenium import webdriver
from selenium.webdriver.common import keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import threading as thread
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
option = EdgeOptions()
option.use_chromium = True
option.add_argument("--headless")
option.add_argument('user-data-dir= C://Users//USERNAME//AppData//Local//Microsoft//Edge SxS//User Data')
driver = webdriver.Edge(executable_path="J://edgedriver_win64//msedgedriver.exe",options = option)
driver.get('https://web.whatsapp.com')
wait = WebDriverWait(driver, 60)
But I am getting an error:
File "h:\Huzaifa\Python\Project\OpenCV\Spam1.py", line 19, in
driver = webdriver.Edge(executable_path="J://edgedriver_win64//msedgedriver.exe",options
= option) TypeError: init() got an unexpected keyword argument 'options'
I tried running it headless and things but it just won't work.
Any help would be massively appreciated. Thanks!
it could be a selenium version issue. The version of selenium you are using do not support the options argument. You can see the documentation for Firefox object that you're using by starting a Python console and:
from selenium.webdriver import Firefox
help(Firefox)

How to solve Captchas with Python Capmonster

I am using Python selenium chromedriver and I want to add Capmonster to my code. Basically if my Code gets the URL, a ReCaptcha appears and I want to get it solved.
My Code
from threading import Thread
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
import os
chromedriver = 'C:\\Users\\yvesb\\OneDrive\\Desktop\\chromedriver\\chromedriver.exe'
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)
def test(driver, url):
driver.get(url)
try:
driver.save_screenshot('C:\\Users\\yvesb\\Downloads\\headless_chrome_test7.png')
finally:
print("screenshot done")
url = "https://www.snipes.com/login"
Thread(target=test, args=(driver, url)).start()
And when it gets the URL a ReCaptcha appears, which I want to get solved with my Capmonster Key.
I suggest you to try this library I've developed some time ago. If you have a set of labelled captchas that service would fit you. Take a look: https://github.com/punkerpunker/captcha_solver
In README there is a section "Train model on external data" that you might be interested in.

Trying to open chrome on my profile with selenium in python 3.8

Every time chrome opens it's not on my profile, so I don't have all of my saved passwords an extensions.
I searched for a while and this is what came out.
Chrome still opens but it's not on my profile.
Can anyone tell me what I've done wrong?
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\Utente\AppData\Local\Google\Chrome\User Data\Profile 1")
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.nike.com/it/launch?s=upcoming")
I think you need a comma after path and then define chrome_options like this:
driver = webdriver.Chrome(executable_path='C:\\path\\to\\chromedriver', chrome_options=options)

How to configure selenium RC, Web driver in ubuntu

I have an ubuntu server and the script that will open particular website(firefox) and perform some operations and closes.
But always I used to get this error
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with stacktrace fxdriver.preconditions.visible...
Here is some of my code
import time
import sys
import json
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from pyvirtualdisplay import Display
from xvfbwrapper import Xvfb
......
......
display = Display(visible=0, size=(1300, 1000))
display.start()
# Initiate the browser
binary = FirefoxBinary('/usr/bin/firefox')
browser = webdriver.Firefox(firefox_binary=binary)
browser.get('http://somesite.com/')
Now When I try to find some element after this getting the above error. Even though added sleep for 30s no use. Can anyone guess whats wrong with this?

Categories

Resources