1

Need help on below to click() i can't click on the Button 'Connexion'. I can locate element in Chrome devtool but my program still fails.

Button HTML :

<button class="btn btn-lg hoverableButton ng-scope" translate="LOGIN" ng-disabled="authenticationCtrl.disableMageConnectButton()" ng-click="onSubmit()">Connexion</button>

I have tried with below code

By button = By.xpath("//button[@class='btn btn-lg hoverableButton ng-scope' and contains(@ng-click, 'authenticationCtrl.onSubmitMage()')]");

WebDriverWait wait = new WebDriverWait(webdriver, 15);
    wait.until(ExpectedConditions.elementToBeClickable(button));
    webdriver.findElement(button).click();

The error Message :

Expected condition failed: waiting for element to be clickable: By.xpath: //button[@class='btn btn-lg hoverableButton ng-scope' and contains(@ng-click, 'authenticationCtrl.onSubmitMage()')] (tried for 15 second(s) with 500 milliseconds interval)

and

no such element: Unable to locate element: {"method":"xpath","selector":"//button[@class='btn btn-lg hoverableButton ng-scope' and contains(@ng-click, 'authenticationCtrl.onSubmitMage()')]"}

I tested the xpath on devtools and xpath and it found the button.

Thanks.

16
  • can you share the URL? Commented Jul 22, 2021 at 9:03
  • it's an intern website of the company you need an accout , vpn ... Commented Jul 22, 2021 at 9:05
  • what happen if you take XPath //button[text()='Connexion'] and click Commented Jul 22, 2021 at 9:09
  • i have other button in other pannel with same name and i try it with adding index like (//button[@translate='LOGIN'])[2] or //(button[contains(text(),'Connexion')])[2] i got the same error Commented Jul 22, 2021 at 9:12
  • As stated by the @cruisepandey try to check for the iframe Commented Jul 22, 2021 at 9:15

1 Answer 1

1

If

webdriver.findElement(button).click();

throws

no such element: Unable to locate element: {"method":"xpath","selector":"//button[@class='btn btn-lg hoverableButton ng-scope' and contains(@ng-click, 'authenticationCtrl.onSubmitMage()'

It could be cause of element is in iframe or locator could not found in DOM.

Since you are saying that it is present in DOM, I would probably say, we may have an iframe issue here.

Iframe :

The tag specifies an inline frame.

An inline frame is used to embed another document within the current HTML document.

In Selenium, we need to switch the driver focus to particular iframe in order to interact with the elements which are inside of the iframe :

driver.switchTo.frame("Frame_ID");

and then you should be able to do :

webdriver.findElement(By.xpath("//button[text()='Connexion']")).click();

Update 1 :

There are two button with same name, I am pretty much sure that xpath index will work

for first button :

(//button[text()='Connexion'])[1]

second button :

(//button[text()='Connexion'])[2]

Update 2 :

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//button[text()='Connexion'])[2]"))).click();
Sign up to request clarification or add additional context in comments.

27 Comments

first thanks for your help . second i have i have other button in other pannel with same name and i try it with adding index like (//button[@translate='LOGIN'])[2] or //(button[contains(text(),'Connexion')])[2] i got the same error. third i try it with iframe id but i have this error No frame element found by name or id lightningjs-frame-usabilla_live it seems that they are not an iframe .
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste (//button[@translate='LOGIN'])[2] and see if your desired element is getting highlighted
yes sir i can find the element in chrome devtool, when i do paste for (//button[@translate='LOGIN'])[2] i can visualize the element but when i run my progam i got the same error message
is it 1/1 entry in DOM ? and when you scroll up you do not see an iframe ?
i updated the question so you can see the HTML, ''is it 1/1 in DOM" i didn't understand that, no they are no iframe. Thanks
|

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.