In my Java/Selenium framework I try to fill in an e-mail address. With manual testing I click the field and a pull down menu is openend. This list is filtered with the values I enter. However with automated testing, this list remains empty.
<div class="k-widget k-multiselect k-multiselect-clearable k-state-hover" unselectable="on" title="" style="">
<div class="k-multiselect-wrap k-floatwrap" unselectable="on">
<ul role="listbox" unselectable="on" class="k-reset" id="create-task-users-list_taglist"></ul>
<input class="k-input k-readonly" style="width: 107.469px;" accesskey="" autocomplete="off" role="listbox" title="" aria-expanded="false" tabindex="0" aria-describedby="create-task-users-list_taglist" aria-owns="create-task-users-list_taglist create-task-users-list_listbox" aria-disabled="false" aria-busy="false">
<span unselectable="on" class="k-icon k-clear-value k-i-close k-hidden" title="clear" role="button" tabindex="-1"></span>
<span class="k-icon k-i-loading k-hidden"></span>
<span style="font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: 100%; font-style: normal; font-weight: 400; letter-spacing: normal; text-transform: none; line-height: 23.1px; position: absolute; visibility: hidden; top: -3333px; left: -3333px;">Assign Users</span>
</div>
<select id="create-task-users-list" multiple="multiple" data-placeholder="Assign Users" data-role="multiselect" aria-disabled="false" style="display: none;">
<option value="1001">User #1(user1#mytestapp.com)</option>
<option value="1002">User #2(user2#mytestapp.com)</option>
<option value="1003">User #3(user3#mytestapp.com)</option>
<option value="1004">User #4(user4#mytestapp.com)</option>
<option value="1005">User #5(user5#mytestapp.com)</option>
<option value="1006">User #6(user6#mytestapp.com)</option>
<option value="1007">User #7(user7#mytestapp.com)</option>
</select>
</div>
I perform the same actions with Selenium, but the list is empty. The following statements are used.
//input element
element.click();
element.sendKeys("user2#mytestapp.com");
//Filtered pull down menu
Select select = new Select(element);
select.selectByVisibleText(testElement.getValue());
Another problem is that this website I am using in my test is developed by a third party and I have no influence here. It is used to support my Website under test.
Why is this happening? Why is the list available during manual testing, but not automated? Is there anything I have to change? Is this in the browser startup?
#Edit:
Clearing the browser cache (Chrome) did not help.
This issue was a bug in the application. The reason that values are shown when testing manual, was that the values were available in the cache. By deleting the cache, including storage removal, the same issue occurs as when testing automated.
It has been reported to the third party and will be solved shortly.
Related
In my application page, have a web table with multiple rows and columns loaded dynamically based on the data added. In a one of the "td" the data will be sometimes a "p" tag or "button" tag (but will look like a link) based on the status of the account on that row. And also I need to click that button to do some additional action. Here i need to validate a case, need to take all the rows and columns data and store it. But while on this particular td, as it varies based on the account status, how can I dynamically check and take the status text like check if it is "button" or "p" control?
Table looks like below
Code for both the rows looks like (sammple)
<td class="Table2Cell account-list-cell va--middle pl--2" tabindex="0" style="width: 24%; min-height: 120px; max-height: 120px;">
<div class="FlexBox FlexBox__direction FlexBox__direction--row FlexBox__justify--start">
<div class="FlexItem FlexItem__align-self--top FlexItem__align-self--base-top">
<svg class="Icon status-action Icon--rotate-0 Icon--size-small-tight" focusable="false" name="icon-alert-circle" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin-top: 2px;">
<use xlink:href="/static/fonts/icons/icon-defs.svg#alert-circle"></use>
</svg>
</div>
<div class="FlexItem FlexItem__align-self--center FlexItem__align-self--base-center">
<div style="padding-left: 4px;">
<button aria-disabled="false" aria-label="Upload Check Image" class="Button px--0 py--0 Button--link" formnovalidate="" type="button" style="min-height: 0px; line-height: 16px; margin-bottom: 5px; margin-top: 5px;">
<span class="Button__text Button__text--link">Upload Check Image</span>
</button>
<p class="text--dark text--small">Action Required
</p>
</div>
</div>
</div>
</td>
=============
<td class="Table2Cell account-list-cell va--middle pl--2" tabindex="-1" style="width: 24%; min-height: 120px; max-height: 120px;">
<div class="FlexBox FlexBox__direction FlexBox__direction--row FlexBox__justify--start">
<div class="FlexItem FlexItem__align-self--top FlexItem__align-self--base-top">
<svg class="Icon status-verified Icon--rotate-0 Icon--size-small-tight" focusable="false" name="icon-checkmark-circle" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin-top: 2px;">
<use xlink:href="/static/fonts/icons/icon-defs.svg#checkmark-circle"></use>
</svg>
</div>
<div class="FlexItem FlexItem__align-self--center FlexItem__align-self--base-center">
<div style="padding-left: 4px;">
<p class="text--regular flex-grow--0">Verified</p>
<p class="text--dark text--small">Status
</p>
</div>
</div>
</div>
</td>
any help on this?
Comma in css selectors button, p.text--regular return both or existing one element. Using the css selector you'll get button or p. Parent element should be a row element. Use it to get an element and check the tag.
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement statusElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button, p.text--regular")));
String tag = statusElement.getTagName();
Both Action Required and Verified, Status is in P tag. However there's a difference between Action Required p tag and that is it has a preceding-sibling (button) that has text Upload Check Image.
I have a work around for this Problem (Only cons is that it has a bad time complexity) :
use findElements() instead :
2 cases :
Let's say for most of the time you see Action Required the do this :
The below code is for a particular td not a list of tds
if(driver.findElements(By.xpath("//span[text()='Upload Check Image']")).size() > 0 ){
// do what ever you wanna do here when **Action Required** is visible in UI.
}
When most of the time it is Verified :
if(driver.findElements(By.xpath("//p[contains(#class, 'text--
regular') and text() = 'Verified']")).size() > 0 ){
// do what ever you wanna do here when **Verified** is visible in
UI.
}
In my web page I want to click on the txtbox which will drop down a list, and then click on the first option. I can't use the selector option since the it isn't a select type. So I am using the Action in selenium to move my mouse to click. When in the web page if I click over the textbox the dropdown will list the items. But in my selenium code it can find the txtbox element, but when I click it, it can't element in the list. I don't think the list appears when I click on the txtbox. Heres my current code:
Webelement txtbox = driver.findElement(By.xpath("//*[#id=\"lob\"]"));
Webelement inpt =driver.findElement
(By.xpath("/html/body/div[2]/div/div/div/div[2]/div/div/div[1]"));
mouseHoverAction(txtbox);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(inpt));
Utils.mouseHoverAction(inpt);
public static void mouseHoverAction(WebElement mainElement){
Actions action = new Actions(driver);
action.moveToElement(mainElement).perform();
action.click();
action.perform();
Log.info("Click action is performed on the selected Product Type");
}
In my Log file it never says that the click action was performed but it does say the textbox was found.
Here is the HTML before I click on textbox:
<div class="ant-select margin___3sLIj ant-select-lg ant-select-single
ant-select-show-arrow" name="lineOfBusiness" style="width: 100%;">
<div class="ant-select-selector">
<span class="ant-select-selection-search">
<input id="lob" autocomplete="off" class="ant-select-selection-search-input"
role="combobox" aria-haspopup="listbox" aria-owns="lob_list" aria-autocomplete="list"
aria-controls="lob_list" aria-activedescendant="lob_list_0"
readonly="" unselectable="on" value="" style="opacity: 0;" aria-expanded="false">
</span>
<span class="ant-select-selection-placeholder">Please select one
</span>
</div>
>
Here is HTML after I click drop down and insepct first element in list "Business Enablement"
<div class="ant-select-dropdown ant-select-dropdown-placement-bottomLeft
ant-select-dropdown-hidden" style="min-width: 205px; width: 205px;
left: 182.984px; top: 614.984px;">
<div>
<div role="listbox" id="lob_list" style="height: 0px; width: 0px; overflow: hidden;">
<div aria-label="Business Enablement" role="option"
id="lob_list_0" aria-selected="false">Business Enablement</div>
<div aria-label="Capital Markets" role="option"
id="lob_list_1" aria-selected="false">Capital Markets</div>
</div>
<div class="" style="height: 256px; overflow-y: auto; overflow-anchor: none;">
<div style="height: 480px; position: relative; overflow: hidden;">
<div class="" style="display: flex; flex-direction: column; transform: translateY(0px);
position: absolute; left: 0px; right: 0px; top: 0px;"><div aria-selected="false"
class="ant-select-item ant-select-item-option ant-select-item-option-active">
<div class="ant-select-item-option-content">Business Enablement
</div>
<span class="ant-select-item-option-state" unselectable="on" aria-hidden="true"
style="user-select: none;"></span>
</div>
<div class="ant-select-item-option-content">Capital Markets
</div>
<span class="ant-select-item-option-state" unselectable="on" aria-hidden="true"
style="user-select: none;"></span>
</div>
<div class="ant-select-item-option-content">Caribbean Banking
</div>
<span class="ant-select-item-option-state" unselectable="on" aria-hidden="true"
style="user-select: none;"></span>
</div>
<div class="ant-select-item-option-content">Cloud
</div>
<span class="ant-select-item-option-state" unselectable="on" aria-hidden="true"
style="user-select: none;"></span>
</div>
</div>
</div>
</div>
</div>
I need help selecting "Business Enablment"
Extra Pics
This is how you can attempt to try it -
Click the dropdown
Right click on the first element of the dropdown, inspect . After the developer option is open, right click on that element, copy full xpath. Now you will need to tweak the xpath to capture everything from the list. Sometimes you can just use //li and get content of the list or sometimes you will have to add * to either table, tr depending on the xpath
Once you get the xpath to capture the list, store it in List
List brand = driver.findElements(By.xpath("use your custom xpath"));
Iterate through the list and store the text
Search for the value you want to click
Click the element when you find
This is one of the method I have written for my project
public void selectBrand(String Brand) {
List<WebElement> brand = driver.findElements(By.xpath("//li"));// this will store all elements from brands dropdown, again you will need to use your custom xpath
for (WebElement brandlist : brand)
{
String brandName = brandlist.getText();// store all text from dropdown
if (brandName.length() > 1) {
if (brandName.contains(Brand))// search for the value to click
{
brandlist.click();// click
}
}
}
}
i need to select the data from Excel file . Here i am using keyword driven framework. This is the HTML code
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<div id="addDialog" class="hidden ui-dialog-content ui-widget-content" style="display: block; width: auto; min-height: 30px; height: auto; max-height: 351.05px; overflow-y: auto;">
<div class="field-container">
<fieldset class="field-container">
<legend>Contracts:</legend>
<a class="select-all" href="#">Select All</a>
<a class="deselect-all" href="#">Deselect All</a>
<select id="addContract" class="searchable" multiple="multiple" style="position: absolute; left: -9999px;">
<option value="93370956">93370956</option>
<option value="93796167">93796167</option>
<option value="94203239">94203239</option>
</select>
<div id="ms-addContract" class="ms-container">
<div class="ms-selectable">
<input class="search-input" type="text" placeholder="filter" autocomplete="off"/>
<ul class="ms-list" tabindex="-1">
<li id="86355560-selectable" class="ms-elem-selectable">
<span>93370956</span>
</li>
<li id="202890296-selectable" class="ms-elem-selectable">
<span>93796167</span>
</li>
<li id="938848030-selectable" class="ms-elem-selectable">
<span>94203239</span>
</li>
</ul>
</div>
I am sending defined data from excel file. I tried some code but they are not selecting all the data from excel file at some point of time code is giving me exception for webElement not found.
TRY #1
List<WebElement> options = driver.findElements(By.xpath("//ul[#class='ms-list']/li/span[contains(text(),'"+testData+"')]"));
for (WebElement option : options) {
if(testData.equals(option.getText()))
option.click();
TRY#2
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ul[#class='ms-list']/li/span[contains(text(),'"+testData+"')]"))).click();
If i have 10 data in list and i am reading them from my Excel file it above codes only select 3 or 4 and then gave me exception.
Then i tried with this one:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='ms-addContract']/div[1]/input"))).sendKeys(testData);
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[#id='ms-addContract']/div[1]/input")).sendKeys(Keys.ARROW_DOWN,Keys.ARROW_DOWN,Keys.SPACE);
Thread.sleep(2000);
//Clear the input text value.
driver.findElement(By.xpath(".//*[#id='ms-addContract']/div[1]/input")).clear();
where it is sending data to filter textbox and selecting the popped up input. But it is taking time and if i don't put delay giving me timeout Exception.
Please help.
I use sendkeys method to enter a value in a Kendo UI autocomplete input field. Then, I tab off the field. After tabbing off the field, the entered value is disappeared.
How can I wait until the entered value is populated on the field before I tab off the field?
<td class="k-edit-cell" role="gridcell" tabindex="0" data-role="editable">
<span class="k-widget k-autocomplete k-header k-state-default" tabindex="-1" role="presentation" style="width: calc(100% - 30px);">
<td class="k-edit-cell" role="gridcell" tabindex="0" data-role="editable">
<input id="ddAssetID" class="k-input" style="width: 100%;" data-bind="value: AssetNumber" data-role="autocomplete" autocomplete="off" role="textbox" aria-haspopup="true" aria-disabled="false" aria-readonly="false" aria-owns="ddAssetID_listbox" aria-autocomplete="both" type="text">
<span class="k-icon k-loading" style="display:none"></span>
Thanks
For the Kendo UI autocomplete box sample (http://demos.telerik.com/kendo-ui/autocomplete/index) you could use the following Java snippet to type "Aus" into the box, wait for the "Austria" element to be clickable, and then click on it so that "Austria" gets added:
driver.get("http://demos.telerik.com/kendo-ui/autocomplete/index");
driver.findElement(By.id("countries")).sendKeys("Aus");
WebElement austria = new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[contains(text(), 'Austria')]")));
austria.click();
assertTrue(driver.findElement(By.id("countries")).getText().contains("Austria"));
I am new to Selenium Web Driver and unable to select element in the list box and getting below error:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"ext-element-13"}
WebElement item = launch.driver.findElement(By.id("ext-element-13"));
Select page_dropdown = new Select(item);
for(int i=0; i<page_dropdown.getOptions().size(); i++)
{
page_dropdown.selectByIndex(i);
System.out.println("Page drop down having values " + page_dropdown.getFirstSelectedOption().getText());
}
<div id="boundlist-1123" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-border-box" tabindex="-1" style="width: 215px; right: auto; left: 574px; top: 140px; z-index: 19000; height: 300px;" data-componentid="boundlist-1123">
<div id="boundlist-1123-listWrap" class="x-boundlist-list-ct x-unselectable" data-ref="listWrap" style="overflow: auto; height: 299px;">
<ul id="boundlist-1123-listEl" class="x-list-plain" aria-disabled="false" aria-hidden="false" role="listbox" data-ref="listEl">
<li id="ext-element-13" class="x-boundlist-item x-boundlist-selected" unselectable="on" role="option" tabindex="-1" data-recordindex="0" data-recordid="3" data-boundview="boundlist-1123">ABC Program : Summary</li>
<li class="x-boundlist-item" unselectable="on" role="option" tabindex="-1" data-recordindex="1" data-recordid="4" data-boundview="boundlist-1123">ABC-001: Poor Control</li>
<li class="x-boundlist-item" unselectable="on" role="option" tabindex="-1" data-recordindex="2" data-recordid="5" data-boundview="boundlist-1123">ABC-002: Low Density </li>
As per provided HTML code, i am expecting it is not Select drop down. so select command may not work here..
secondly if i am correct
<ul id="boundlist-1123-listEl" class="x-list-plain" aria-disabled="false" aria-hidden="false" role="listbox" data-ref="listEl">
is location of your drop down and below one is one of option correct?
<li id="ext-element-13" class="x-boundlist-item x-boundlist-selected" unselectable="on" role="option" tabindex="-1" data-recordindex="0" data-recordid="3" data-boundview="boundlist-1123">ABC Program : Summary</li>
here you may need to use sendkeys
driver.findElement(By.xpath("//*[#role='listbox']")).sendKeys("ABC Program : Summary");
you can also use xpath=//*[#data-ref='listEl'] in above code if there are more listbox elements in page
if above one does not work, just try by directly clicking on required option
driver.findElement(By.xpath("//*[contains(text(),'ABC Program : Summary')]")).click();
if even above one does not work, then you need to click on ul and then required option.
there may be change in locators, if they are not working let me know, will try for another xpath