for some reason the following xpath will not click when i use the click command in selenium ide.The link iam trying to click is called devices. How can i get this to click?
xpath=//div[2]/section/nav/div[3]/div/div/span
Here is the full code:
<div title="Devices" class="asm-source-list-group-view"> <header role="heading" aria-hidden="true">Devices</header> <div><div role="link" aria-selected="true" title="Devices" class="asm-source-list-item-view cw-being-hovered"> <span class="title" aria-hidden="true">Devices</span> <span class="count cw-hidden" aria-hidden="true">0</span></div><div role="link" aria-selected="false" title="Assignment History" class="asm-source-list-item-view"> <span class="title" aria-hidden="true">Assignment History</span> <span class="count cw-hidden" aria-hidden="true">0</span></div></div></div>
CodePudding user response:
If you are getting an error that this element is currently not visible or something, You have to implement WebDriverWait
until the element is visible.
So try this
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@]/header/div[@]/span")));
element.click();
When you give an Xpath try to give proper class names as well.
Xpath = //div[@]/header/div[@]/span
CodePudding user response:
To click the element you can use the following XPath:
//div[@title="Devices"]//div[@title="Devices" and @]//span
CodePudding user response:
Assuming the text Devices is unique,
you can use the Xpath as //span[contains(text(),'Devices']
and then use click on this. it should work with driver.findElement(By.Xpath("//span[contains(text(),'Devices']").click();
CodePudding user response:
Check the Xpath your given her if it's unique if it is and it still want click i suggest you try these 3 ways to click for me one of them always do the job:
Using Actions Lib :
WebElement elemCN = driver.findElement(By.xpath("your path"));
int widthCN = elemCN.getSize().getWidth();
act.moveToElement(elemCN).moveByOffset((widthCN / 2) - 2, 0).click().perform();
Using JS :
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement SubmitPaiement = driver.findElement(By.xpath("your path"));
js.executeScript("arguments[0].click();", SubmitPaiement);
And finaly the normal .click()