0

I need to click on or find element "Compute vmSwitch". I tried many ways using xpath (class & contains), cssSelector as well, but could not able to locate element:

driver.findElement(By.xpath("//span[contains(@class,'nopadding vm-create-text-style-3 block-with-text-4  ng-binding') and contains(text(), 'Compute vmSwitch')]")).click();

The code is given below:

<div class="w-full"><br>
<img class="img-responsive center-block m-t-47" src="/src/icon/background/create_vm_img5.png">
<div class="col-md-12 m-t-md  wordwrap">
<p class="nopadding vm-create-text-style-3 block-with-text-4  ng-binding">
Compute vmSwitch</p>
</div>
5
  • 1
    Can u please share html code for which u want to click ? Commented Oct 20, 2017 at 12:00
  • <div class="w-full"><br> <img class="img-responsive center-block m-t-47" src="/src/icon/background/create_vm_img5.png"> <div class="col-md-12 m-t-md wordwrap"> <p class="nopadding vm-create-text-style-3 block-with-text-4 ng-binding"> Compute vmSwitch</p> </div> Commented Oct 20, 2017 at 12:13
  • Hi Ankur, i want to click on 'Compute vmSwitch', for which i tried all possible ways.. Commented Oct 20, 2017 at 12:16
  • //*[text()='Compute vmSwitch'] or //p[text()='Compute vmSwitch'] , can u try this Commented Oct 20, 2017 at 12:19
  • In ur xpath y u have use span tag . i'm not seeing any span tag in ur code? u can use it this way //p[contains(@class,'nopadding vm-create-text-style-3 block-with-text-4 ng-binding') and contains(text(), ' Compute vmSwitch')] Commented Oct 20, 2017 at 12:22

1 Answer 1

1

Why do you try with the span tag? If this is your html:

<html>
 <head></head>
 <body>
  <div class="w-full">
   <br> 
   <img class="img-responsive center-block m-t-47" src="/src/icon/background/create_vm_img5.png"> 
   <div class="col-md-12 m-t-md wordwrap"> 
    <p class="nopadding vm-create-text-style-3 block-with-text-4 ng-binding"> Compute vmSwitch</p> 
   </div> 
  </div>
 </body>
</html>

you could try:

    WebElement elem2= driver.findElement(By.xpath("//div[@class='w-full']"));
    elem2.findElement(By.xpath(".//p[text()=' Compute vmSwitch']")).click();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Ankur & Durden for your help. But unfortunately i couldn't able to locate the element by using either ways..
Can you please share ? ur url

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.