1

I want to click on "cmd('abcdef:perxform',{'id':'5'},true)".

html code --->    <div class="abcdef_button_small" onclick="if (!check_health(1,3)) return; if (!check_timers(1,$(this))) return; $('#dialog_abcdefs .disabled_controls').show(); cmd('abcdef:perxform',{'id':'5'},true); ">AAAA</div>


xpath code --->    //*[@id="abcdef_5"]/div[4]
xpath code --->    /html/body/div[2]/div[3]/div[22]/div[2]/div[4]/div[3]/div[5]/div[4]
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@onclick='('abcdef:perxform',{'id':'5'},true);']" ))).click()

driver.find_element(By.XPATH,"//div[@onclick=('abcdef:perxform',{'id':'5'},true); ]").click()

the above didn't work.

Berk
  • 33
  • 5

1 Answers1

1

Using the onclick attribute with dynamic values to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[onclick*='show'][onclick*='perxform'][onclick*='5']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@onclick, 'show') and contains(@onclick, 'perxform')][contains(@onclick, '5')]"))).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
    

References

You can find a couple of relevant detailed discussions in:


Proof of concept

Not sure if the HTML was tailored as <div> tags are seldom clickable. However here is poc:

poc

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Unfortunately it didn't work. i want to click "perxform',{'id':'5'}". There are values with too many IDs. – Berk Mar 01 '23 at 21:22
  • It didn't work again :/ – Berk Mar 01 '23 at 21:41
  • driver = self.driver driver.find_element_by_xpath("//div[@onclick=\"if (!check_health(2,3)) return; if (!check_timers(1,$(this))) return; $('#dialog_abcdefs .disabled_controls').show(); cmd('abcdef:perform',{'id':'3'}, true); \"]").click() I tried with "katalon". recorder gave this code and it worked in "katalon". but when I tried this code "vs code" it still didn't work. – Berk Mar 01 '23 at 22:57
  • Did you get a chance to look at the preface of the answer where I mentioned about _dynamic values_ and _`WebDriverWait`_? Probhably you are messing up things. Just copy paste the code and retest and let me know the status. – undetected Selenium Mar 01 '23 at 23:00
  • WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@onclick, 'show') and contains(@onclick, 'abcdef:perxform')][contains(@onclick, '5')]"))).click() clicked with this code. I just need to open the "dropdown menu" it is in for it to work. Does it work without clicking the "dropdown menu"? – Berk Mar 01 '23 at 23:19
  • @Berk You never mentioned about any dropdown in your question. It was only evident you were invoking `click()`. Hence the answer. Feel free to raise a new question as per your new requirements. – undetected Selenium Mar 01 '23 at 23:21
  • @Berk _clicked with this code_: Glad to be able to help you. – undetected Selenium Mar 01 '23 at 23:24