Reputation: 884
I'm wondering if anyone else has experienced this issue. I've got a website utilising twitter bootstrap, at one point in my script I open a modal, I go through and interact fine with several objects within that modal (text input, dropdown, checkbox). But when I come to clicking the submit button at the end nothing happens.
As far as selenium is concerned it clicked it, and if I watch the screen while its running and could see the button highlight as if clicked, but nothing happens. If I then try to click on it afterwards still nothing happens other than the button highlights. If I then hit RETURN or ENTER then it fires fine...
I've tried instead of clicking sending ENTER or RETURN but they all do the same thing and am at a complete loss, I identify the object via XPATH which as far as I can see looks right...
Here's a chunk out of the code, bear in mind that everything before this works...
threadSesh.driver.findElement(By.xpath(".//*[@id='createDeal']").click();
threadSesh.driver.findElement(By.xpath("html/body/div[3]/div[2]/div/dl/dd[1]/input").clear();
threadSesh.driver.findElement(By.xpath("html/body/div[3]/div[2]/div/dl/dd[1]/input").sendKeys("MyNewProject");
Select myDropDown = new Select(threadSesh.driver.findElement(By.xpath("html/body/div[3]/div[2]/div/dl/dd[3]/select")));
myDropDown.selectByVisibleText("Buy Out");
threadSesh.driver.findElement(By.xpath(".//*[@id='ProjectOriginator']/li/input").click();
threadSesh.driver.findElement(By.xpath(".//*[@id='ProjectOriginator']/li/input").sendKeys("John smith");
threadSesh.driver.findElement(By.xpath("(//a[contains(text(),'Create')])[2]").click();
Its the final line that just does nothing... Any suggestions would be very much appreciated!
Also worth pointing out I am using ie and cannot test this in chrome or FF (neither version is allowed on this website I'm testing, its an internal platform).
Another piece of potentially useful information, the button isn't a button in fact but a ref of some kind that's been made to look like a button using the twitter bootstrap stuff, the source for it looks like this: -
<a class="btn btn-small btn-info" type="button" style="margin-right: 7px; padding-left: 15px; padding-right: 15px;" data-bind="click: ok" href="#">Create</a>
If I record it in the seleneium addin for firefox it outputs this: -
driver.findElement(By.xpath("(//a[contains(text(),'Create')])[2]")).click();
Upvotes: 4
Views: 2583
Reputation: 884
I managed to come up with a solution to this, only by sheer luck though. Basically before I click on the Cancel or Create links I was interacting with some tagit inputs and had to do some fiddling to get them to work.
These tagits were in one div (html/body/div[3]/div[2]
) within the modal and the links were in another (html/body/div[3]/div[3]
) and this fiddling around seemed to have stopped Selenium from seeing the other div somehow, although I'm not sure how.
To fix the issue I simply added in a click of the modal at the top level (html/body/div[3]
) and then it found the lower level links fine! How this fixes it I don't know but at least my scripts work fine again now...
Upvotes: 5