-2

this is a strange one (for me) that I can't get my head around.

I have an application, I recorded a basic test with the Selenium IDE and exported this and have tried to make the code more robust. I am having issues with this element:

<input class=" " id="P400_ADD_MEDIUM_BUT" onclick="void(0);" type="button" value="Add Emission">

It should be fairly simple, it has an id so initially I thought I would use this to locate the element and click it:

driver.findElement(By.id("P400_ADD_MEDIUM_BUT")).click();

When I watch the test run, the button is highlighted blue (this application has a two stage blue colour, dark blue when the mouse button is down, lighter blue when mouse released) - the colour I see is light blue - however, nothing happens (a popup should appear.)

I have tried changing this to XPath and using the following: //input[@id='P400_ADD_MEDIUM_BUT']

driver.findElement(By.xpath("//input[@id='P400_ADD_MEDIUM_BUT']")).click();

But still the same result. I played the recorded script back in the IDE and this works fine. I should mention that the test has to run in IE (it's an internal application and IE is the only browser used internally) - but I am stumped.

IE is 11, latest selenium and IE driver.

Anyone have any ideas?

5
  • When you refresh the page, Your id attribute value is getting changed? Commented Sep 18, 2017 at 11:20
  • The id is staying constant - I have refreshed and checked before and after and the line never changes. Commented Sep 18, 2017 at 11:24
  • can you share the html of the section that contains this button? also you should share the exact error, is not visible / is not clickable / is not found or what kind of error, the error is important in detecting the root cause. Commented Sep 18, 2017 at 11:26
  • There is no error - nothing at all - just the behaviour as described. Commented Sep 18, 2017 at 11:28
  • As far as I understand selenium clicks button successfully, but nothing happens. It's possible that javascript action is not already bound to this button when selenium attempt to click it. Try to wait some time after driver.get() before you execute your click();. Commented Sep 18, 2017 at 11:29

1 Answer 1

0

Try any of these below code.

Note:- Before going to click this button, provide few seconds of wait So your driver may able to find the webelement.

For wait I am using Explicit Wait method.

new WebDriverWait(driver, 60).until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//input[@type='button'][@value='Add Emission']"))));   //Wait for 60 seconds.
driver.findElement(By.xpath("//input[@type='button'][@value='Add Emission']")).click();

OR

Try to click on button using Javascript Executor method.

WebElement button = driver.findElement(By.xpath("//input[@type='button'][@value='Add Emission']"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", button);
Sign up to request clarification or add additional context in comments.

2 Comments

It seems like your IE Browser settings needs to be changed, so before going to Run my script, Please modify settings this way.. refer this Answer...stackoverflow.com/questions/46234351/…
Setting protected and running it via JavascriptExecutor seems to have done the trick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.