I can not locate element for this box to click on to get the date picker to popup
Any help would be appreciated
when I inspect element this is what I see...Xpath does not work either
<input ng-disabled="viewOnly" class="formInput effectiveDates ng-pristine ng-isolate-scope hasDatepicker ng-empty ng-invalid ng-invalid-required ng-not-modified ng-touched" autocomplete="off" name="effectiveStartDate" ng-required="true" placeholder="Select/Enter date(mm/dd/yyyy)" type="search" ng-model="authObj.authStartDate" value="" ng-keydown="preventUserEnterDateInfo($event)" datepicker="" minimumdate="02/27/2020" ng-change="effectiveDateChange(authObj.authStartDate)" ng-class="(authListForm.$submitted && authListForm.effectiveStartDate.$invalid)?'reqd':''" id="dp1582663746532" required="required">
The desired element is an Angular element so to locate/click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.formInput.effectiveDates.ng-pristine.ng-isolate-scope.hasDatepicker.ng-empty.ng-invalid.ng-invalid-required.ng-not-modified.ng-touched[name='effectiveStartDate'][placeholder*='Enter date']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#class='formInput effectiveDates ng-pristine ng-isolate-scope hasDatepicker ng-empty ng-invalid ng-invalid-required ng-not-modified ng-touched' and #name='effectiveStartDate'][contains(#placeholder, 'Enter date')]"))).click();
You can try click using JavascriptExecutor.
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
or you can try click using coordinates:
Actions builder = new Actions(driver);
builder.moveToElement(element, 10, 25).click().build().perform();
I noticed that the 'type'-tag is set to Search. If you want a browser to recognize it as a Date-Input, change it to type="date". The browser itself will invoke its default datepicker.
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 want to click "Action" button and select the option "Update Reference data".
Here is my code
Thread.sleep(30000);// To load the page
driver.findElement(By.xpath("//*[#id=\"spend_mgmt_actions_menu\"]")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[id=\"upgradeRefData_button\"]")).click();
I also tried this, but got the same exception
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"spend_mgmt_actions_button\"]")));
driver.findElement(By.className("button show-right-icon f-dropdown-facade actions-list-button plan-action-button")).click();
Thread.sleep(20000);
But when I run the code it gives:
No Such Element Exception unable to locate.....
Below is the HTML code copied from browser by selecting the element.
<button id="spend_mgmt_actions_button"
class="button show-right-icon f-dropdown-facade actions-list-button plan-action-button"
aria-hidden="false" aria-haspopup="true" data-dropdown="spend_mgmt_actions_menu" tabindex="0">
<span>Actions</span><span class="icon icon-right fa fa-caret-down"></span></button>
<button id="upgradeRefData_button" class="list-item dd-item" aria-disabled="false"
data-dropdown-item="" role="menuitem" tabindex="0" title=""><span>Update Reference Data</span>
</button>
You were close. To click() on the element with text as Actions and then to click() the element with text as Update Reference Data you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.button.show-right-icon.f-dropdown-facade.actions-list-button.plan-action-button#spend_mgmt_actions_button>span"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.list-item dd-item#upgradeRefData_button>span"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='button show-right-icon f-dropdown-facade actions-list-button plan-action-button' and #id='spend_mgmt_actions_button']/span[text()='Actions']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='list-item.dd-item' and #id='upgradeRefData_button']/span[text()='Update Reference Data']"))).click();
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 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();
I try to send Keys to an input field via Java Selenium. I get the NoSuchElementException every time. I also tried everything from this Solution: NoSuchElementExeption, selenium unable to locate element. Thanks in Advance!
driver.findElement(By.xpath("//input[#class='pull-left ng-pristine ng-validng-empty ng-touched']")).sendKeys(t + Keys.ENTER);
<input class="pull-left ng-pristine ng-valid ng-empty ng-touched" ng-model="TagInputCtrl.tagInput" uib-typeahead="tagSuggestion for tagSuggestion in TagInputCtrl.getTagSuggestions($viewValue)" select-on-comma="" select-on-whitespace="" select-on-blur="" typeahead-focus-first="false" tag-select="TagInputCtrl.onEnter" tag-select-model="ngModel" sprd-max-input-length="50" ng-show="ngModel.length < TagInputCtrl.validatorOptions.tags.max" ng-focus="TagInputCtrl.focused = true" ng-blur="TagInputCtrl.focused = false" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-4377-3960" style="" type="text"/>
To send a character sequence as the desired element is an Angular element so you need to induce WebDriverWait for the element to be clickable and you can use either of the following solution:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.pull-left.ng-pristine.ng-valid.ng-empty.ng-touched[ng-model^='TagInputCtrl']"))).sendKeys("Tim");
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#class='pull-left ng-pristine ng-valid ng-empty ng-touched'][contains(#ng-model,'TagInputCtrl')]"))).sendKeys("Tim");
There can be two things for NoSuchElementException :
Your locator is not correct.
If this is the case then you can try with this xpath :
//input[contains(#class,'pull-left ng-pristine ng-valid ng-empty ng-touched') and #ng-model='TagInputCtrl.tagInput' and #ng-focus='TagInputCtrl.focused = true']
Your webpage is integrated with Angular. So the provided xpath should work.
Your input tag might be in iframe/frame/frameset.
If this is the case, then I would recommend you to switch the focus of your driver to the particular iframe, to interact with desire element.
for switching you can try this code :
driver.switchTo().frame(name_or_id)
Generally, iframe tag contains name or id attribute, in case if both of them aren't available , you can go ahead with
driver.switchTo().frame(index)
or
driver.switchTo().frame(iframe_element)
Here, iframe_element is a web element.
Hope this helps.