I try to locate a dynamic button element after click search but it cannot locate it. The Create Account CID sometimes is not clickable and sometime can click.
<div class="pzbtn-rgt" data-click="...">
<div class="pzbtn-mid" data-click="....">
<img src="https://10.204.137.86:5111/prweb/PRWebLDAP3/SstGGrXNazw%5B*/webwb/zblankimage.gif" alt="" class="pzbtn-i">
Create Individual CID
<img alt="" src="https://10.204.137.86:5111/prweb/PRWebLDAP3/SstGGrXNazw%5B*/webwb/zblankimage.gif" class="pzbtn-i">
The create individual CID is the one need clicks on.
I using absolute xpath but it still fails. I had tried with many ways. Please help. Thanks.
WebDriverWait waitCIDBtn = new WebDriverWait(driver, 10);
waitCIDBtn.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[3]/div[4]/div/div/form/div[1]/div/div/div/div/div[1]/table/tbody/tr/td/div[2]/table/tbody/tr/td/div/div/span/div/div[4]/div/div/div/div[4]/div/div/span/button/div/div/div/div")));
WebElement createCID = driver.findElement(By.xpath("/html/body/div[3]/div[4]/div/div/form/div[1]/div/div/div/div/div[1]/table/tbody/tr/td/div[2]/table/tbody/tr/td/div/div/span/div/div[4]/div/div/div/div[4]/div/div/span/button/div/div/div/div"));
createCID.click();
As you are trying to invoke click() on the element so, instead of using visibilityOfElementLocated() you need use elementToBeClickable() and you can use either of the following Locator Strategies:
Using cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.pzbtn-mid>img.pzbtn-i[src*='zblankimage']"))).click();
Using xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='pzbtn-mid']/img[#class='pzbtn-i' and contains(#src, 'zblankimage')]"))).click();
Related
This is the button of the page I need to click:
<div _ngcontent-jnk-c107="" class="btn btn-primary btn-outline" tabindex="0" ng-reflect-router-link="/opportunity/1">VIEW</div>
I can't use the text view in the locator as there are other 22 buttons in the same page with the same text.
The only difference between them is that router link, which I don't know how to call. I already tried with Link text and partial link text, with no results.
In case ng-reflect-router-link attribute value is unique for this element you can use the following XPath locator:
//div[#ng-reflect-router-link='/opportunity/1']
To click() on the element with text as VIEW with respect to the ng-reflect-router-link attribute you can use either of the following Locator Strategies:
Using cssSelector:
driver.findElement(By.cssSelector("div.btn.btn-primary.btn-outline[ng-reflect-router-link='/opportunity/1']")).click();
Using xpath:
driver.findElement(By.xpath("//div[#class='btn btn-primary btn-outline' and #ng-reflect-router-link='/opportunity/1']")).click();
However, as the element is a Angular element, to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
Using cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.btn.btn-primary.btn-outline[ng-reflect-router-link='/opportunity/1']"))).click();
Using xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='btn btn-primary btn-outline' and #ng-reflect-router-link='/opportunity/1']"))).click();
I'm trying to identify the element. I want to identify the "address your concerns.". I am able to reach up to div tag but i need to reach the text in the div tag.
HTML:
<span class="Linkify">
<div>
<div>
address your concerns.
</div>
</div>
</span>
I am trying to identify the text "address your concerns" so can anyone help me with this in chrome browser, I am trying?
To identify the element using Selenium you need to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following Locator Strategies:
cssSelector:
WebElement cssElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.Linkify > div > div")));
xpath:
WebElement xpathElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[#class='Linkify']/div/div[contains(., 'address your concerns')]")));
Try doing it using XPath to locate your div element, something like this "//span[#class='Linkify']/div/div" and then use getText() method on this div to get your text.
Unable to locate the element using id/name/xpath/CSSSelector
Tried the below codes and both failed to give response
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\'form\']/p/button/span")));
driver.findElement(By.xpath("//*[#id=\'form\']/p/button/span")).click();
and
WebElement checkout = driver.findElement(By.xpath("//[#id=\'form\']/p/button/span"));
checkout.click();
HTML
<button type="submit" name="processCarrier" class="button btn btn-default standard-checkout button-medium" style="">
<span> Proceed to checkout <i class="icon-chevron-right right"></i> </span>
</button>
Try Following CSS Selector.
WebElement checkout = driver.findElement(By.cssSelector("button.standard-checkout span"));
checkout .click();
Or yon can use WebDriverWait and Css Selector.
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.standard-checkout span")));
element.click()
Probably you are getting org.openqa.selenium.InvalidSelectorException because you should use * after // to match any node(tag) who has id=form or the specific tag name.
change it to //*[#id='form']/p/button/span
Or use more specific like
xpath : //button[#name='processCarrier'] equivalent CSS : button[name='processCarrier']
And use implicit/explicit wait to make element available in DOM to perform actions.
Presumably you will invoke click() on the <button> element, so you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.standard-checkout.button-medium[name='processCarrier']>span"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='button btn btn-default standard-checkout button-medium' and #name='processCarrier']/span"))).click();
I'm automating some website in which I need to log out. I'm facing a hard time in this code:
WebDriverWait wait = new WebDriverWait(d, 10);
WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user logout")));
Category_Body.click();
d.findElement(By.id("logout_user")).click();
Thread.sleep(1000);
HTML:
<a class="user logout" title="Sign out" data-target="#confirm_popup" data-toggle="modal"></a>
Error:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"user logout"}
Try the following code for that:
WebDriverWait wait = new WebDriverWait(d, 10);
WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".user.logout")));
Category_Body.click();
PS: You can do this with ExpectedCondition.elementToBeClickable, also.
Hope it helps you!
I think the issue is with the identifier
You have used
WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user logout")));
But according to your HTML
<a class="user logout" title="Sign out" data-target="#confirm_popup" data-toggle="modal"></a>
The link have no id called "User Logout"
With out using id try to use class By.findElementByClassName("user logout")
As a Second solution, try to use xpath ( which will work most of the time )
If both the solutions are not usable you can use the JavascriptExecutor ( The elements which are hard to capture can be easily handled with JavascriptExecutor )
NOTE: The main issue is with you using "user logout" when there is no such ID
Cheers
As per your to locate the desired element to logout within the Model Box you need to induce WebDriverWait for the element to be clickable and you can use either of the the following options:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.user.logout[title='Sign out'][data-toggle='modal']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='user logout' and #title='Sign out'][#data-toggle='modal']"))).click();
I am trying to click on the logout link to log out of the application using selenium xpath. The web page has user image link and when it is clicked a drop down for Logout link is displayed. When I try to locate the xpath of the Logout link, it does not go anywhere. Any thoughts, please ?
Here is my page source for that element. Don't know if this gives any idea.
<div data-v-5fa222fc="" class="user"><!----> <a data-v-5fa222fc="" class="user-menu">QA#some.com <img data-v-5fa222fc="" src="data:image/png;base64,iVBORw....uQmCC"></a></div>
As per the HTML you have shared to click on the user image you need to induce WebDriverwait for the next desired element to be clickable and you can use either of the solutions:
partialLinkText:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("QA#some.com"))).click();
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.user a.user-menu img[src*='data:image/png;base64,']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='user']//a[#class='user-menu']//img[contains(#src,'data:image/png')]"))).click();
Try this xpath:
//a[contains(., 'QA#some.com')]