Selenium Chrome Driver: Javascript on click function. element not visible or nothing happens

527 views Asked by At

So I'm working on a script at work that automates VMWare's Airwatch token generation for MDM. It was functioning, but they updated the server/Airwatch Console and this javascript onclick function broke it. I've already searched through various forums and posts and have no luck getting it to work. If I have selenium find the element and .click() on it, I get the not visible/not interactable error. Currently, I have:

addButton=driver.find_element_by_css_selector("a.add.profile.small")
webdriver.ActionChains(driver).move_to_element(addButton).perform().click(addButton)

And no errors occur but it doesn't do anything.

When manually moving the mouse over the button it changes to a hand instead of the pointer and the button background color changes.

Here's a snippet of the element properties:

        <a class="add profile small" onclick="F5_r2u();F5_Event_common(event);
    try{return(eval(F5_Invoke_eval_event(null,F5_jsBody(function(){addTagRow(this);
        }))))}finally{try{F5_Event_finally(event)}catch(e){}}">Add</a>

selector: #\31 34364e7_Tag_Plural > a
xpath: //*[@id="134364e7_Tag_Plural"]/a

Any Advice?

Pretty sure I need to have Selenium hover over the button, then click on it, or execute the javascript. Not sure how to do that though.

Screenshot of Add Button

1

There are 1 answers

6
ewwink On

when you switch from tab User to Tags it need to wait until ADD button visible

# click tab Tags
tabTags = driver.find_element_by_css_selector('tab.tags.selector').click()
# wait until visible
addButton = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a.add.profile.small')))
addButton.click()

using ActionChains maybe like this

tabTags = driver.find_element_by_css_selector('tab.tags.selector')
addButton = driver.find_element_by_css_selector("a.add.profile.small")

actions = webdriver.ActionChains(driver)
actions.click(tabTags)
actions.click(addButton)
actions.perform()