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

Philip Schlesinger December 9, 2015

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?????

 

5 answers

1 accepted

0 votes
Answer accepted
Philip Schlesinger December 14, 2015

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();
0 votes
Lasantha Goonetilleke September 19, 2019

I have similar issue. Looking for a solution. 

0 votes
Reg Hawkins February 8, 2018

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

0 votes
Philip Schlesinger December 10, 2015

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.

0 votes
Philip Schlesinger December 10, 2015

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...

Suggest an answer

Log in or Sign up to answer