How interact with dcc.DatePickerSingle using selenium - python

I am testing a dashboard created with dash and I have a couple of dcc.DatePickerSingle. I want to test these by introducing some dates and then also test that the result generated by the dashboard is equal to the expected value.
I show the code I am using
import pytest
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
import pytest
from selenium import webdriver
import sys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from time import sleep
URL = 'http://127.0.0.1:8001/'
#pytest.fixture
def browser():
# Initialize ChromeDriver
driver = Chrome("./chromedriver")
# Wait implicitly for elements to be ready before attempting interactions
driver.implicitly_wait(10)
# Return the driver object at the end of setup
yield driver
# For cleanup, quit the driver
driver.quit()
def test_dates(browser):
browser.get(URL)
data_start ="Hola"
search_input1 = browser.find_element_by_id('my-date-picker-start')
search_input1.send_keys(data_start)
The error I got after many different attend is
ElementNotInteractableException
To run this the command is pipenv run python -m pytest
Is this element not iterable (I douth that) or I am doing something wrong (Very likely)?

You should use explicit wait rather than implicit wait.
So, remove driver.implicitly_wait(10) (and never use it until you are clearly understand how implicit wait works) and try this:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
search_input1 = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.ID, "my-date-picker-start")))
search_input1.send_keys(data_start)

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)

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()

Python selenium click button by class not working

I'm trying to click a button with its class but it throws an ElementNotInteractableException.
Here is the website HTML code
Here is the code I'm using
driver = webdriver.Chrome('chromedriver.exe', chrome_options=options)
driver.get('https://physionet.org/lightwave/?db=noneeg/1.0.0')
def get_spo2hr(subject):
driver.find_element_by_xpath("//select[#name='record']/option[text()='"+subject+"']").click()
driver.find_element_by_id('ui-id-3').click()
driver.find_element_by_id('viewann').click()
driver.find_element_by_id('viewsig').click()
driver.find_element_by_id('lwform').click()
driver.find_element_by_css_selector(".fwd").click()
driver.save_screenshot('screenie.png')
get_spo2hr('Subject10_SpO2HR')
One thing is (as said in other answers) the unstable css selector prefer xpath
But the main thing is that the div is overlapping the a item at the dom rendering
Just wait one second to wait until the dom loads:
import time
time.sleep(1)
Example code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
driver = webdriver.Chrome()
driver.get('https://physionet.org/lightwave/?db=noneeg/1.0.0')
def get_spo2hr(subject):
driver.find_element_by_xpath("//select[#name='record']/option[text()='"+subject+"']").click()
import time
time.sleep(1)
driver.find_element_by_id('ui-id-3').click()
driver.find_element_by_id('viewann').click()
driver.find_element_by_id('viewsig').click()
driver.find_element_by_id('lwform').click()
driver.find_element_by_xpath('/html/body/div[1]/main/div/div/div/form/div[3]/table/tbody/tr/td[2]/div/button[3]').click()
driver.save_screenshot('screenie.png')
get_spo2hr('Subject10_SpO2HR')
I always prefer getting elements using their xpath, of course, in suitable situations. With that being said, I modified your code to find the forward button using its xpath and it works.
Here is the modified code:
driver = webdriver.Chrome('chromedriver.exe', chrome_options=options)
driver.get('https://physionet.org/lightwave/?db=noneeg/1.0.0')
def get_spo2hr(subject):
driver.find_element_by_xpath("//select[#name='record']/option[text()='" + subject + "']").click()
driver.find_element_by_id('ui-id-3').click()
driver.find_element_by_id('viewann').click()
driver.find_element_by_id('viewsig').click()
driver.find_element_by_id('lwform').click()
driver.find_element_by_xpath('/html/body/div[1]/main/div/div/div/form/div[3]/table/tbody/tr/td[2]/div/button[3]').click()
driver.save_screenshot('screenie.png')
get_spo2hr('Subject10_SpO2HR')

Categories

Resources