JumpIntoTheWater
JumpIntoTheWater

Reputation: 1336

Can't click an element

I'm having an issue clicking an element on the IE11 browser (the web only supports IE browser).
I have tried everything I know so far but nothing really works. The element is being found, and according to the test being passed, seems like it was clicked, but nothing really happened. It wasn't executed. That is the HTML:

<li tabindex="-1" title="forward" class="ms-crm-CommandBarItem ms-crm-CommandBar-Menu ms-crm-CommandBar-Button" id="email|NoRelationship|Form|Mscrm.Form.email.Forward" style="display: inline-block; white-space: pre-line;" command="email|NoRelationship|Form|Mscrm.Form.email.Forward"><span tabindex="-1" class="ms-crm-CommandBar-Button ms-crm-Menu-Label" style="max-width: 200px;"><a tabindex="0" class="ms-crm-Menu-Label" onclick="return false"><img tabindex="-1" class="ms-crm-ImageStrip-forwardedemail_16 ms-crm-commandbar-image16by16" style="vertical-align: top;" src="/_imgs/imagestrips/transparent_spacer.gif"> <span tabindex="-1" class="ms-crm-CommandBar-Menu" style="max-width: 150px;" command="email|NoRelationship|Form|Mscrm.Form.email.Forward"> forward to rec</span><div class="ms-crm-div-NotVisible"> 
new object has been created </div>  </a> </span> </li>

These are just some of the things I have tried and the following XPath syntax actually works for other elements in the same page.

WebDriverWait wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(30));
var element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//[@id='email|NoRelationship|Form|Mscrm.Form.email.Forward']")));
element.Click();

var element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id='email|NoRelationship|Form|Mscrm.Form.email.Forward']")));IJavaScriptExecutor executor = (IJavaScriptExecutor)_webdriver;
executor.ExecuteScript("arguments[0].click();", element);

I have tried using the Action class as well in order to click, but nothing works. Also using only FindElement(By.Id('')). In some cases, it looks like there is a mouse hover on the element, but again, nothing really executes the click.

UPD: I'm trying to click a button actually which later in the hierarchy there's a span and a tags. I found out that manually, pressing the buttons work perfectly. The button is getting "locked" when first finding the element with Selenium even before trying to click on it.

Upvotes: 0

Views: 1302

Answers (1)

Ratmir Asanov
Ratmir Asanov

Reputation: 6459

Try on the following code:

WebDriverWait wait = new WebDriverWait(_webdriver, TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("a.ms-crm-Menu-Label")));
element.Click();

PS: It clicks on the link. (a tag).

Hope it helps you!

Upvotes: 1

Related Questions