Home > Net >  Selenium webdriver cannot reach button (manually too)
Selenium webdriver cannot reach button (manually too)

Time:01-12

I have a problem with Selenium. In a normal browser (Firefox, Chrome) I can go to a page and click a button. In Selenium browser (Chrome) - I can't. Also - I can't even do it manually in Selenium Chrome. The button does not respond. What could be the cause of this?

Edit: I'd like to send some message. I filled data, but I still have a problem with sending it (button is clicked, but message is not sent) I provided CAPS LOCK comment in my code where the problem is.

I mean black button (Abschicken) example url: https://home.mobile.de/sample#contact

Any help would be greatly appreciated

My code:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

caps = DesiredCapabilities().CHROME
caps["pageLoadStrategy"] = "eager"
browser = webdriver.Chrome(ChromeDriverManager().install(), desired_capabilities=caps)

browser.get('https://home.mobile.de/sample#contact')
time.sleep(5)
# Closing popup
browser.find_element_by_xpath("//button[@class='sc-bczRLJ iBneUr mde-consent-accept-btn']").click()

user_name = browser.find_element_by_name("name")
user_mail = browser.find_element_by_name("email")
user_message = browser.find_element_by_id("contactText")

time.sleep(0.7)
user_name.send_keys("example name")

time.sleep(0.7)
user_mail.send_keys("[email protected]")

time.sleep(0.7)
user_message.send_keys("My message. Good morning sir")   

browser.find_element_by_name("sendCopyToMe").click()
# Clicking ##### BUT IT NOT CAUSE SENDING A MESSAGE @@@@@
browser.find_element_by_xpath("//button[@class='btn btn-inverse span20 contactSend']").click()

CodePudding user response:

You did not share your code, not the error you received.
So I don't know what you did wrong.
The following code works:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)

url = "https://home.mobile.de/AUTOMOBILE-WIERSCHEM#contact"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[class*=accept]"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[class*=contactSend]"))).click()
  • Related