What could be the reason behind the click method not functioning properly in Python Selenium?

Having trouble with the click() method in Selenium Python? Despite searching through all available methods in the Selenium documentation, I am struggling to automate tasks on this specific URL.

from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains

ser = Service("D:\chromedriver")
op = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=ser, options=op)
actionChains = ActionChains(driver)

driver.get('https://cultivatedculture.com/mailscoop/')

driver.maximize_window()
sleep(2)
# log = driver.find_element(By.LINK_TEXT, "LOG IN")
# sleep(2)
# log.click()


for i in range(3):
    #-----------------------------------------------------
    name = 'jay kakadiya'
    domain = 'gmail.com'

    inp = driver.find_element(By.ID ,'name')
    inp.send_keys(name)

    inp2 = driver.find_element(By.ID ,'domain')
    inp2.send_keys(domain)
    sleep(1)
    btn = driver.find_element(By.XPATH, '//*[@id="find_btn"]')
    sleep(1)

    btn.click()
    actionChains.move_to_element(btn).click().perform()
    print("press click")
    #-----------------------------------------------------------

    # if i == 0:
    #
    #     popup1 = driver.find_element(By.XPATH('//*[@id="jsSignupModalForm"]/div[2]/div/p[5]/span'))
    #     sleep(1)
    #     actionChains.move_to_element(popup1).click().perform()
    #     popup2 = driver.find_element(By.XPATH('//*[@id="jsLoginModalForm"]/div[2]/div/div[1]/div[3]'))
    #     sleep(1)
    #     actionChains.move_to_element(popup2).click().perform()
    #     driver.find_element_by_id('jsUserLoginModal').send_keys('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bacadbddd3c8d388888d8dfadcd6d5cdd7d3d4dfc894d9d5d7">[email protected]</a>')
    #     driver.find_element_by_id('jsUserLoginModal').send_keys('jaykakadiya63522')
    #     sleep(1)
    #     popup3 = driver.find_element(By.XPATH, '//*[@id="jsLoginModalForm"]/div[2]/div/div[2]/div"]')
    #     actionChains.move_to_element(popup3).click().perform()

Answer №1

Before proceeding, ensure you have entered your Full Name and Company Website in the designated fields. Once this is complete, click on the button labeled Find It. It is important to implement the WebDriverWait function for the element_to_be_clickable() method. You can utilize various locator strategies for this task:

driver.get('https://cultivatedculture.com/mailscoop/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#name[name='name']"))).send_keys("jay kakadiya")
driver.find_element(By.CSS_SELECTOR, "input#domain[name='domain']").send_keys("gmail.com")
driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#find_btn > span > span"))))

Note: Don't forget to include the necessary imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Browser Snapshot:

Answer №2

If you are searching for a way to select an element using CSS, try the following selector:

button#find_btn span

This CSS selector is specific to HTMLDOM.

To interact with this element after waiting for it to be clickable, you can do so by implementing explicit wait as shown below:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#find_btn span"))).click()

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

It's not clear why a loop would be necessary for this task.

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

Popup text alert remains persistent in SeleniumPlus test on Internet Explorer

Currently, I am using a method called VerifyAndDismissAlert() in an automated test. try{ WebDriver WD = WebDriver(); Alert alert = WD.switchTo().alert(); alert.accept(); String alertText = alert.getText(); Pause(1); ...

What are the steps for installing modules and packages on Linux without an internet connection?

Is there a way to install the modules and packages listed below offline in Linux? import time from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.rem ...

I'm encountering a webdriver issue in my IntelliJ IDE when trying to run Selenium tests

While working on my Selenium project, I encountered an error in IntelliJ IDE that did not occur when using Eclipse IDE. Attach is a snapshot showcasing the issue. The code runs without any issues in Eclipse, and I have already included the necessary depend ...

Error encountered while executing Selenium Web Driver's executeScript method: [JavascriptError: missing ) after argument list] with name: 'JavascriptError'

return driver.executeScript("\ console.log('Error: Incorrect selection');\ $('option:selected', 'select[name='who']').removeAttr('selected');\ $('select[name='who'] ...

Python automation with Selenium for downloading dynamic captchas

With a large number of registration numbers to check regularly, I decided to develop a script that could automate this process for me. The process involves visiting the website: On this website, I need to enter a registration number in one field and solv ...

What is the best way to confirm the presence of an element on a webpage?

While working on feature descriptions for a web service using Watir, I am tasked with validating the behavior of the service in different browser conditions. Specifically, my goal is to confirm the visibility of an element (in this case, a simple link) und ...

WebDriverManager unable to connect with PhantomJSDriver

I am facing an issue with using WebDriverManager. I want to use PhantomJSDriver without manually setting a system property like this: System.setProperty("phantomjs.binary.path", "E:/phantomjs-2.1.1-windows/bin/phantomjs.exe"); In my pom.xml, I have these ...

Guide to using Python and Selenium to extract the titles of each search result

I am currently learning Python and attempting to extract search results from python.org using the Selenium library. Here are the steps I want to follow: Open python.org Search for the term "array" (which will display the results) Paste the list of searc ...

Difficulty with automating tests using selenium in Linux: Unable to automatically close Firefox browser

When conducting automation testing for web GUI in Linux using Selenium (Selenium RC), I encountered an issue. While running Selenium tests on Windows yielded successful results with Firefox closing automatically after completing the test, the same could no ...

Attempting to utilize Selenium to input data into a text field on a web page

Trying out different versions of WebElement userid = driver.findElement(By.xpath and WebElement email = driver.findElement(By.id("email")); has resulted in syntax errors for me. If you need a visual reference, check out this image of the textbox ...

Converting for loop to extract values from a data frame using various lists

In the scenario where I have two lists, list1 and list2, along with a single data frame called df1, I am applying filters to append certain from_account values to an empty list p. Some sample values of list1 are: [128195, 101643, 143865, 59455, 108778, 66 ...

A guide on choosing the checkbox based on the HTML using Selenium WebDriver with Python

I am facing an issue with selecting a checkbox using Selenium. Here is the HTML structure: <input id="diDataCheck" ng-model="$parent.DIDATA.IsSet" name="Mode" type="checkbox" class="ng-pristine ng-untouched ng-valid ng-empty" xpath="1"> Despite try ...

Eternal Flow Protractor

Having some trouble with utilizing Protractor for testing my end-to-end application built with Angular. Running into timeouts despite already starting the Selenium server and Chrome driver. ...

RSelenium in conjunction with Chrome fails to render the entire webpage

Struggling to navigate using RSelenium, I am faced with missing element text and incomplete page loading. This issue seems to be specific to Chrome, as it works fine on FireFox. An example code snippet: library(RSelenium) rD <- rsDriver(port = 4567L, ...

GeckoDriver and Selenium encounter Exec format error on MacOS resulting in OSError: [Errno 8]

While developing a bot using Firefox Gecko Driver, I keep encountering error messages originating from the following lines of code: from selenium import webdriver browser= webdriver.Firefox() Despite adding all the necessary files to my path, including ...

Executing Selenium tests: utilizing the webdriver.wait function to repeatedly call a promise

Currently, I am using Selenium ChromeDriver, Node.js, and Mocha for testing purposes... I am facing a dilemma at the moment: The driver.wait function seamlessly integrates with until. I have a promise, which we'll refer to as promiseA. This pro ...

Encountering an issue while performing Python Selenium testing on the login and logout features

Encountering an error message... Error: AttributeError: 'LoginTestCase' object has no attribute 'driver' Here is the code snippet: from selenium import webdriver; from selenium.webdriver.common.keys import Keys import time import unit ...

Managing TAB behavior in Selenium

I am attempting to switch between two tabs and came across the following code snippet: ArrayList<String> tabs2 = new ArrayList<String> (page.getWindowHandles()); System.out.println(tabs2.size()); page.switchTo().window(tabs2.get( ...

Tips on selecting an element with xpath in Selenium WebDriver (It usually does the trick, but not working on this particular URL)

Attempting to access an input field on the website by utilizing xpath. Normally, this method works for all URLs, but for this specific one, I am unable to click on the input field using selenium webdriver. The webdriver successfully loads the page but fai ...

Attempting to utilize Selenium code in order to continuously refresh a webpage until a button becomes clickable

After receiving valuable assistance from the online community, I managed to create a script that can navigate through a webpage and join a waitlist. The issue arises when the 'join waitlist' button is not clickable because the waitlist is not ope ...