1

Can you help me locate this radiobutton with the help of Selenium(Python) located on a page with a rather strange structure at "https://www.avans.pl/reklamacja"

enter image description here

location of the element on the page with the possibility of using the Click() function on it.

Code trials:

import datetime
import time

# from selenium import webdriver
# from selenium.webdriver.common import keys
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.select import Select
# from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.support.select import Select
from selenium.webdriver.common import keys
from selenium.webdriver.common.by import By
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver import Firefox

driver = Firefox(executable_path=GeckoDriverManager().install())

def MailAdrCreator():
    datadzis = datetime.date.today()
    tab_date = str(datadzis).split("-")
    adr = tab_date[0]+tab_date[1]+tab_date[2]
    email = "test.formularzy.terg+"+adr+"@gmail.com"
    return email

driver.get("https://www.avans.pl/reklamacja")
driver.maximize_window()
driver.find_element_by_id("cc_form_1").send_keys("Jan")
driver.find_element_by_id("cc_form_3").send_keys("Kowalski")
driver.find_element_by_id("cc_form_36").send_keys(MailAdrCreator())
driver.find_element_by_id("cc_form_841").send_keys("02321484339")
driver.find_element_by_id("cc_form_843").send_keys("pralka, lodówka, radio")
driver.find_element_by_id("cc_form_363").send_keys("ABC12962019621")
driver.find_element_by_id("cc_form_1292_0").click()
# driver.find_element_by_id("cc_form_1292_1").click()
# time.sleep(5)
driver.close()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Paulina
  • 11
  • 1

2 Answers2

0

Try the below code:

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
# to accept the cookies information
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".c-alert_close"))).click()

# scroll to the title of the page to view the 'Tak' radio button
driver.execute_script("arguments[0].scrollIntoView(true)", driver.find_element(By.CSS_SELECTOR, ".c-headline_title.a-typo.is-primary"))

radio_btn = driver.find_element(By.CSS_SELECTOR, ".a-form_radio.is-customCheckbox_label #cc_form_1292_0")
# clicking on the radio button using javascript
driver.execute_script("arguments[0].click();", radio_btn)
AbiSaran
  • 2,538
  • 3
  • 9
  • 15
  • Counter question, why to use `execute_script()` when the generic `click()` which is much proven and effective achieves the same result? – undetected Selenium Jan 16 '23 at 20:13
  • You can refer this post: https://stackoverflow.com/questions/34562061/webdriver-click-vs-javascript-click. Generally, for the exceptions - 'Element is not clickable at point(x,y). Other element would receive the click while working Selenium webdriver.' and 'Element not interactable selenium', using JavascriptExecutor can resolve these issues. – AbiSaran Jan 17 '23 at 05:03
  • I don't see OP mentioning about facing `Element is not clickable at point(x,y)` kinda exception. – undetected Selenium Jan 17 '23 at 11:39
  • Not here, I am saying generally we can use javascript if we face those kinds of exceptions. I used it, it helped me in a lot of scenarios, in my official and offline projects, especially for the above two exceptions. – AbiSaran Jan 17 '23 at 12:07
  • What about the answer I posted to your question, regarding the CDP version and Selenium Dev-tools version mismatch? – AbiSaran Jan 17 '23 at 12:10
0

To click on the associated with either of the text Tak / Nie you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Clicking on Tak:

    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-synerise='Tak']//parent::label[@class='a-form_radio is-customCheckbox_label']"))).click()
    
  • Clicking on Nie:

    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-synerise='Nie']//parent::label[@class='a-form_radio is-customCheckbox_label']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352