How to configure selenium RC, Web driver in ubuntu - python

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?

Related

headless_ie_selenium not working with 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)

Python Scrape Issue - Sublime, Chrome

First off - no experience with Python, Sublime Text or Selenium - please be kind..
I am having an issue building a scraper in Python - using Sublime text, Selenium and Chrome. I have updated to the latest Python, Pip and downloaded the correct Chrome Driver. The webpage pops up fine, but get errors.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
#from selenium.webdriver.common.ui import WebDriverWait - commented out due to error
#from selenium.webdriver.common import expected_conditions as EC - commented out due to error
import time
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
driver.get ("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
print(driver.find_element(by=By.CLASS_NAME, value='ng-tns-c210-4 text-promo-1').text)***
wait = WebDriverWait(driver, 20)
driver.get("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
elem=wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.ng-tns-c210-4.text-promo-1')))
print(elem.text)
Your class name is actually multiple class names so using css selector.
Outputs:
$80.99
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

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.

Python Selenium Edgedriver stuck on showing "data;," in the address bar, not opening web page

I had this issue on 2 different systems, on first PC it went away after a reboot, on the other it had not gone away
Below is a portion of the code in question:
I masked some things on purpose
The edge browser is stuck on openign page with data;, shown in the address bar. It does not go beyond this.
I checked that Edge and Edgedriver are the same exact version, if it matters.
I cannot use Chrome or any other drivers for this project
Why doesn't selenium advance past the opening of the program?
I also have an error in CMD when it launches: [9704:11992:0305/080544.278:ERROR:storage_reserve.cc(164)] Failed to open file to mark as storage reserve: C:\Users**\AppData\Local\Temp\scoped_dir3468_1483298328\Default\Code Cache\js on selenium
How do I fix this?
# importing required package of webdriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.opera.options import Options
from selenium.webdriver.support.wait import WebDriverWait
import schedule
import time
from random import randint
def job():
while True:
# Instantiate the webdriver with the executable location of MS Edge
browser = webdriver.Edge(r"C:\Users\*****\Desktop\msedgedriver.exe")
sleep(2)
browser.maximize_window()
sleep(2)
browser.get('https://********/) #masked the name of website on purpose
try:
# Get the text box to insert Email using selector ID
myElem_1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'anti-myhub')))
sleep(3)
# Entering the email address
myElem_1.click()

Categories

Resources