How to click on span button written inside serveral div tag in Selenium webdriver
How to click on span button written inside serveral div tag in Selenium webdriver
I am trying to click on span button written inside div tag. The div id ="ROOT/Incident Management"
is the subtag of 2 more div tag.
div id ="ROOT/Incident Management"
Project code below
I want to click on below Button "Incident Management". The below codes are tried,
1. driver.findElement(By.xpath("//*[@id='cwcNavPanel']/div/div[3]/div/span")).click();
2. driver.findElement(By.xpath("//span[contains(@class,'x-panel-header-text') and contains(text(), 'Incident Management')]")).click();
3. driver.findElement(By.xpath("//div[@class='x-panel-header x-panel-header-noborder x-unselectable x-accordion-hd']//span[@class='x-panel-header-text']")).click();
4. driver.findElement(By.xpath("//div[@class='x-panel x-panel-noborder x-tree x-panel-collapsed']//span[@class='x-panel-header-text']")).click();
Project code below
<div id="ROOT/Incident Management" class="x-panel x-panel-noborder x-tree x-panel-collapsed" style="width: auto;">
<div class="x-panel-header x-panel-header-noborder x-unselectable x-accordion-hd" id="ext-gen91" style="cursor: pointer;">
<span class="x-panel-header-text" id="ext-gen95">Incident Management</span>
</div>
</div>
There are no issues with your locators, all of them should work. Are you getting any exception? Also, are you adding enough wait time before locating this element?
– theGuy
Sep 6 '18 at 15:25
Have you tried driver.findElement(By.Id("ext-gen95")).click() ?
– Ywapom
Sep 6 '18 at 16:04
@user2807505 What is the exception if you are getting ?
– Ishita Shah
Sep 7 '18 at 5:28
@Ywapom I tried your code and getting below exception Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: "method":"id","selector":"ext-gen95" (Session info: chrome=68.0.3440.106) (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
– user2807505
Sep 7 '18 at 15:17
1 Answer
1
Thank you very much for your quick reply.
I added the below line and it is wroking fine.
driver.findElement(By.xpath("//span[contains(@id, 'ext-gen') and text()='Incident Management']")).click();
The explanation is: span contains id 'ext-gen'(not exact id but comparable to like command in sql) and having text like 'Incident Management'.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Project code below <div id="ROOT/Incident Management" class="x-panel x-panel-noborder x-tree x-panel-collapsed" style="width: auto;"> <div class="x-panel-header x-panel-header-noborder x-unselectable x-accordion-hd" id="ext-gen91" style="cursor: pointer;"> <span class="x-panel-header-text" id="ext-gen95">Incident Management</span> </div> </div>
– user2807505
Sep 6 '18 at 14:43