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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

7 Comments

Unfortunately it didn't work. i want to click "perxform',{'id':'5'}". There are values with too many IDs.
It didn't work again :/
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.
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.
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"?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.