1

I want to click the "Akkoord" button but I am unable to do that. I already tried different methods but they are not working. Any help will be appreciated. enter image description here

one of the codes I tried.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.demorgen.be/nieuws')

time.sleep(20)
driver.find_elements_by_class_name('message-component message-button no-children pg-accept-button')[0].click() 
2

use xpath or css

css :

[class="message-component message-button no-children pg-accept-button"]


driver.find_elements_by_css_selector('[class="message-component message-button no-children pg-accept-button"]')[0].click() 

xpath:

//*[@class="message-component message-button no-children pg-accept-button"]

driver.find_elements_by_xpath('//*[@class="message-component message-button no-children pg-accept-button"]')[0].click() 

find_elements_by_class_name expects single class name as argument thats why its not working as space in class indicates multiple classes.

THe find by class actually uses css under the hood. So if you want to find element having multiple class . You can replace space with '.' (THis works only in python)

driver.find_elements_by_class_name('message-component.message-button.no-children.pg-accept-button')[0].click() 

Update

The element is inside iframe

frame = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR,
    "#sp_message_container_404503 iframe")))
driver.switch_to_frame(frame)
driver.find_element_by_css_selector(
    '[class="message-component message-button no-children pg-accept-button"]').click()
3
  • Thanks for your response. I tried your suggested methods but it's gave me the same error NoSuchElementException Jan 28 at 20:05
  • @TauqeerSajid its inside iframe updated the answer
    – PDHide
    Jan 28 at 20:34
  • thanks problem solved Jan 28 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.