Selenium WebElement.click() does not actually click element underneath "issuetype-suggestions"

Hi all,

We're testing out some custom JavaScript that changes the Description field when the Issue Type field is changed in the Create Issue dialog. I basically put listeners on "issuetype-field", "issuetype-suggestions", and "issuetype-single-select".

If I manually open a browser and click on Issue Type and change the Issue Type value myself by hand, the Create Issue dialog works as expected...and my JavaScript works without issue.

I then wrote some Selenium2 / WebDriver code to driver.findElement() WebElement objects and then execute the .click() method on those WebElement objects.

If I Debug execute the Selenium2 / WebDriver code within IntelliJ IDEA and manually step my way through the Selenium2 / WebDriver code, the Create Issue dialog works as expected...and my JavaScript works without issue.

However, if I Run execute the Selenium2 / WebDriver code within IntelliJ IDEA, the Create Issue dialog seems to stop working as expected...and so my JavaScript fails.

Here is my Selenium2 / WebDriver code:

  • To change the issue type, I first need to click on the Issue Type drop-down (it has the id "issuetype-suggestions"):
    • Code:

      By byObject = By.id("issuetype-single-select");
      driver.findElement(byObject).click();
    • Expected: the "issuetype-suggestions" section appears underneath
    • Actual (whether Debug or Run in IntelliJ IDEA) : matches Expected (yay!)
  • I next need to select an entry within the "issuetype-suggestions" section.  Unfortunately, the entries don't have id attributes; instead, they have titles.  Hence:
    • Code: 

      By byObject = By.cssSelector("div#issuetype-sugestions a[title=Task]");
      driver.findElement(byObject).click();
    • Expected: 
      • the "issuetype-suggestions" section disappears
      • the Issue Type changes to Task
      • the Description updates to whatever the JavaScript is supposed to do
    • Actual (if stepping through code in Debug mode): matches Expected (yay!)
    • Actual (if instead in Run mode):
      • the "issuetype-suggestions" section disappears
      • the Issue Type does not change!!!

I've tried all kinds of things to remedy this in Run mode under the assumption that maybe there's some code which need to load behind the scenes before I execute the .click() method on the Task entry within "issuetype-suggestions" – thus a pause of some sort is necessary:

  • WebDriverWait.until() with an ExpectedConditions clause that checks for both the "issuetype-suggestions" and Task title exist
  • Thread.sleep(5000)
  • using a JavascriptExecutor to check document.readyState == "complete"

None of those work.  Help?????

 

4 answers

1 accepted

0 votes
Accepted answer

I figured out one workaround, but it's a hack, so hoping somebody else will know a better way than this...

Example code to select "Bug" from the list of issue types which appear in the "issuetype-suggestions" div:

jQuery('div#issuetype-suggestions .active').removeClass('active');
jQuery('div#issuetype-suggestions a[title="Bug"]').parent().addClass('active');
jQuery('div#issuetype-suggestions a[title="Bug"]').click();

I've also tried: * having Selenium2 / WebDriver click on the <img> node instead of the <a>: {code}By byObject = By.cssSelector("div#issuetype-sugestions a[title=Task] img");{code}, and * having Selenium2 / WebDriver click on the <li> node which is the parent of the <a> node: {code}By byObject = By.cssSelector("div#issuetype-sugestions a[title=Task]").findElement(By.xpath("..")); Still no luck...

Additional things I've tried: * having a JavascriptExecutor click the <a> with JS * having a JavascriptExecutor mouseover the <a> and then click it with JS * modifying the class attribute for the <a> to add the additional class "active" * physically moving the mouse to hover over the <a> which is going to be clicked during a brief Thread.sleep pause In all of these cases as well as the cases described above, the click() being sent by Selenium or its JavascriptExecutor is not activating the JS JIRA uses to actually change the Issue Type field to the Issue Type selected from the drop-down. There's got to be some action/event I can generate in Selenium WebDriver directly or via a JavascriptExecutor that will properly tell JIRA to change the Issue Type, but I haven't found it. So for now, I insert a 10-second delay after "issuetype-suggestions" appears...and then manually click the Issue Type with my mouse. Somebody please help me.

you need something like //span[text()="Epic"]

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

204 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you