What could be causing my Selenium URL_to_be statement to fail?

Why won't Selenium recognize my manual visits to publish0x.com? Does anyone have a solution for this?

I need to complete the captcha manually on the login page and then have the script continue after logging in and landing on the main page.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
import datetime
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import sys
from selenium.webdriver.support.ui import WebDriverWait

def waitForLoad(inputXPath):
    Wait = WebDriverWait(driver, 10)
    Wait.until(EC.presence_of_element_located((By.XPATH, inputXPath)))

email = '
password = '

options = Options()
options.add_experimental_option("detach", True)
options.add_argument("--window-size=1920,1080")
## options.add_argument("user-data-dir=/Users/vadim/Library/Application Support/BraveSoftware/Brave-Browser")
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
driver_path = '/usr/local/bin/chromedriver'
driver = webdriver.Chrome(options=options, executable_path=driver_path)
driver.get('https://www.publish0x.com/login')
waitForLoad('//*[@id="email"]')
E_Mail_vak = driver.find_element_by_xpath('//*[@id="email"]')
E_Mail_vak.send_keys(email)
Pass_vak = driver.find_element_by_xpath('//*[@id="password"]')
Pass_vak.send_keys(password)
frame = driver.find_element_by_xpath('//iframe[contains(@src, "recaptcha")]')
driver.switch_to.frame(frame)
Captcha = driver.find_element_by_xpath("//*[@id='recaptcha-anchor']")
Captcha.click()
wait = WebDriverWait(driver, 500)
wait.until(EC.url_to_be("publish0x.com"))
driver.get('https://www.publish0x.com/newposts')
post = driver.find_element_by_css_selector('#main > div.infinite-scroll > div:nth-child(1) > div.content')
title = post.find_element_by_css_selector('h2 > a').text
author = post.find_element_by_css_selector('p.text-secondary > small:nth-child(4) > a').text
title.click()
slider = driver.find_element_by_xpath('//*[@id="tipslider"]')

Answer №1

Here are a couple of methods to tackle this issue, one involves utilizing an Input statement as shown below:

options.add_argument('--disable-gpu')#For properly seeing the outputs
input("Please do the captcha and press any key...)

With this approach, the user would need to fill in the required data before proceeding by pressing any key.

The alternative method is incorporating a try and except block.

try:
    driver.find_element_by_id("some-element")

except NoSuchElementException:
    #do something like
    print("Captcha Failed or Incomplete...")

In this case, make sure to substitute the element id "some-element" with an element that is exclusively available post-user login, such as elements like Profile_nav or Settings. If the element is not found, it indicates that the user didn't complete the captcha.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why is the raise_for_status() function not being triggered when using pytest for requests?

Within this block of code, there is a class called StsAPI with a method named _get_authorize_token. class StsAPI: def _get_authorize_token(self) -> str: try: resp = requests.post(settings.AUTHORIZATION_SERVIC ...

What is the best way to retrieve "Results" data from a JSON file in order to perform calculations using NumPy?

Just beginning my Python journey with Boto3, working on parsing a JSON file: Student = [{"Student_ID": 1, "Name":"Erik", "ExamSubject": "English", "Result": "72.3", "ExamDate": "9/12/2020", "Gender": "M"}, {"Student_ID": 2, ...

Converting HDF5 data from MATLAB to a Pandas DataFrame using Python

I am facing an issue while trying to load .mat files with HDF5 data into Python as a Pandas DataFrame. Here is my current code: f2 = h5py.File("file.mat") f2['data'] Upon running this, I get the following output: <HDF5 dataset "data": shape ...

Combining multiple dictionaries of dictionaries in Python by adding up their values to create a unified dictionary

How can I combine the dictionaries within a dictionary, excluding the main keys, and aggregating the values of similar keys across dictionaries? Input: {'first':{'a': 5}, 'second':{'a': 10}, 'third':{&apo ...

What is the correct way to utilize "%.02f" in the Python format method?

As a newcomer to Python, I recently made the switch to Python 3 and am currently getting comfortable with the format() function. My objective is to display temperatures in floating-point format using the print() function, for example: temperature = [23, ...

Assessing performance after each training iteration

Currently in the process of setting up a workflow with the tensorflow object detection API. I've prepared tfrecords for both my training set (4070 images) and validation set (1080 images). The training runs for 400 iterations before moving to evalua ...

A method for determining the average of a set of averages stored in a dictionary

Recently, I created a function that takes my dictionary, classes, as its parameter: def find_avg(classname): average = {} for classnames, grades in classes.items(): average[classnames] = sum(grades) / len(grades) print(average) classes ...

Automate the execution of webdriver/selenium tests when a form is submitted

I am currently faced with a challenge in setting up an application that will automate some basic predefined tests to eliminate manual testing from our workflow. The concept is to input a URL via a user-friendly form, which will then execute various tests ...

What are some ways to optimize the efficiency of this function to save time?

I have a DataFrame series that contains sentences, some of which are quite lengthy. Additionally, I possess two dictionaries with words as keys and integers as counts. It's worth noting that not all words from the strings appear in both dictionaries ...

Avoiding the use of thread.sleep in dynamically populated lookup field options in Selenium

I am currently working with a dynamic lookup Salesforce component on my webpage. https://i.stack.imgur.com/lxr3q.png <input lightning-basecombobox_basecombobox="" id="input-19" type="text" role="textbox" autocomp ...

SQLAlchemy: Sorting data based on the result of a different order by query

I have a table called Fulfillment with two columns: status and creation date. My goal is to display the data in descending order by creation date if the status is 'open', and ascending order by creation date if the status is 'closed'. A ...

Automate text input using Selenium and Python: a guide to filling in a Wikipedia textarea

I'm seeking help with Selenium - specifically, how to input text into a textarea (wiki textarea). The original HTML is provided below. Your assistance in figuring this out would be greatly appreciated. Thank you! <textarea class="textarea long-f ...

What is causing the "property object is not callable" error when attempting to use bulk_create in Django for inserting data that includes foreign keys?

I am currently working with Django 2.17 and a SQLite 3.26 database, attempting to import data from a csv file. Initially, I used the get_or_create method for insertion, but found it to be too slow. As a result, I started testing out bulk_create for faster ...

Executing Python scripts from a shared directory

Can individuals without Python installed run a Python Selenium script as long as all dependencies are available in a shared directory? For example, if the entire Python folder and its libraries are placed in a shared directory, would users be able to exec ...

Discovering all the strings that are exactly 5 characters long, containing 1 digit and 4 letters, and exploring all possible group combinations

I'm looking for a regex pattern that can count all the groups of strings with a length of 5 containing 1 digit (0-9) and 4 small letters (a-z), meeting the following criteria: 1 digit and all letters are different For example: 1abcd 1 digit, 2 le ...

Encountering an error message: "log4j:WARN - Ensure the log4j system is initialized

Creating a new Java package called ICICI; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.Desir ...

Discovering the hidden input value using the id and name attributes in Python with Beautiful Soup 4 (bs4

Greetings to all members of the SO community. Recently, I encountered a minor issue while attempting to parse HTML. I typically use the bs4 module for this purpose and it has been working well for me until now. When scraping data, I usually look for hidden ...

Maximizing Data Retrieval with Selenium for Optimal Efficiency

Currently, I am working on developing a Selenium code using Java with the following functionality: Open a browser and navigate to a specified URL. Locate the search box on the webpage, enter the keyword polices, and initiate the search. The search result ...

Warning: The variable "color" has been assigned before being declared as a global variable in Python

Looking at the code snippet below, there is an interesting message: "SyntaxWarning: name 'color' is assigned to before global declaration global color" Despite my initial declaration of global color before assigning it a value, this warning is ...

Retrieving a JavaScript variable's value in Selenium with Python

rwdata = driver.find_elements_by_xpath( "/html/body/div[2]/div/div/div/form[2]/div[2]/table/tbody") This table contains the value of variable r as text/javascript type. for r in rwdata: print(r.text) if r.text != "Booked": ...