0

There are many buttons sharing the same class. May have to go with clicking the link /account/logout'.

This is the code I'm trying to use:

input class="btnRed text-uppercase fo_white" value="Logout" onclick="window.location.href='/account/logout';" type="button" 
María Antignolo
  • 388
  • 4
  • 17
JSA
  • 21
  • 4

4 Answers4

0

Hard to say because you didn't provide enough info, but you could probably make it work by using value attribute. Something like this if you are using java.

driver.findElement(By.cssSelector("[value='Logout']")).click();

Not pretty solution, but give it a try:

driver.findElement(By.cssSelector(".btnRed.text-uppercase.fo_white")).click();
acikojevic
  • 915
  • 1
  • 7
  • 16
  • it dint work.it flagged an error again: Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: button[value='Logout'] – JSA Apr 25 '17 at 08:46
  • Edited my code, try now and paste exception if you get one. – acikojevic Apr 25 '17 at 08:52
  • Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: [value='Logout'] – JSA Apr 25 '17 at 08:53
  • OK, I added nasty solution in my post, try it and see if you are getting exception again. – acikojevic Apr 25 '17 at 08:58
  • i had tried that earlier as well. but it gave me a javascript error: JavaScript error: line 1: TypeError: chatWindow is null – JSA Apr 25 '17 at 09:01
  • What, javascript error? Ok, you are doing something wrong, can't help you. You are not showing us your code and you are getting errors which are inconsistent with my tips so who knows what is wrong here. – acikojevic Apr 25 '17 at 09:12
  • Hope this part of code helps. The site is not a public URL . HTML code:
    HTML code :
    – JSA Apr 25 '17 at 09:21
0

Looking at your HTML DOM this command will work for you:

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

Let me know if it works for you.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Looking at your HTML, this should work

driver.findElement(By.xpath("//input[@value='Logout'][@type='button']")).click();

Let me know if it works.

Anuj Teotia
  • 1,303
  • 1
  • 15
  • 21
  • dint work. Unable to locate element: //input[@value='Logout'][@type='button'] – JSA Apr 25 '17 at 09:20
  • Then check for any frame change or page change. If there is any of the case then you have to first switch it to that particular frame/page. Then only this xpath will work. – Anuj Teotia Apr 25 '17 at 09:28
0

Is your element visible/enabled? In order to select an element, it must be present in your DOM. If the element is activated through an event, it cannot be selected until the event occurs.

Take a look at this post. This other post also have good ideas.

Community
  • 1
  • 1
Bob Rivers
  • 5,261
  • 6
  • 47
  • 59