wait for element to be enabled protratcor - selenium

Again, this question might be easy or already asked but i am not able to find any answer to this. All i get is to check if element is clickable but that is not working for me.
Is there any simple solution to wait for an element until it becomes enabled. I have set of dropdowns in my application and other dropdown get selectable only when value is selected in previous dropdown.
I tried below code but it is not working.
var element = element(by.css('[id*="uxSeries"] select'));
browser.wait(protractor.ExpectedConditions.elementToBeClickable(element), 10000);
Error message i am getting:
Failed: stale element reference: element is not attached to the page
document
HTML for dropdown before it get enabled:
<select name="GalleryControl$uxSeries" onchange="OnChangeScript" id="uxSeries" disabled="disabled" style="width:215px;">
<option selected="selected" value="">All Series</option>
<option value="Value1">Option1</option>
<option value="Value2">Option2</option>
<option value="Value3">Option3</option>
<option value="Value4">Option4</option>
<option value="Value5">Option5</option>
</select>
After i select value in my first dropdown, disabled="disabled" property goes away from dropdown.
Can i wait for browser until it is enabled or Disabled property is no more?

Failed: stale element reference: element is not attached to the page document
This exception occurred due to changing of element, as you are saying I have set of dropdowns in my application and other dropdown get selectable only when value is selected in previous dropdown means when it's getting enable, it changes their position or some attribute value may be disabled attribute become change that's why you're in trouble.
You should try first to wait until this element become stale from disabled state using protractor.ExpectedConditions.stalenessOf(), then find again this element when it is in enable state as below :-
var EC = protractor.ExpectedConditions;
#find disabled select element first
var disabledSelect = element(by.css("select#uxSeries[disabled='disabled']"));
#now wait until this becomes stale from disabled state
browser.wait(EC.stalenessOf(disabledSelect), 10000);
#now find enabled select element
var enabledSelect = element(by.css("select#uxSeries"));
#now do your further steps

Related

Jaws screen reader IE 11 select tag issue

I have some issues with IE 11 and Jaws. Please take a look at the example below.
Simplified code example:
<input type="text" />
<span role="alert" aria-live="assertive" id="err"></span>
<select id="colours">
<option value="White">White invalid</option>
<option value="Green">Green invalid</option>
<option value="Red">Red</option>
<option value="Blue">Blue</option>
</select>
var i = 0;
$('#colours').on('keyup', function (e) {
if ($(this).prop('selectedIndex') < 2) {
$('#err').html('an error has occurred ' + i++);
}
else {
$('#err').html('');
}
});
jsfiddle: https://jsfiddle.net/obwapffq/2/
Basically, I am validating the selected element in a dropdown list (in the example 'white' and 'green' values are invalid). I am only using the keyboard's up and down buttons to change the selected value. If an invalid option is selected, I update the content of a span element with the appropriate error message. The span element has role="alert" and aria-live="assertive". I have 2 issues:
If the selected option is invalid, the error message is read out, but the selected option is not read out and so the user does not know what option is invalid i.e. what option caused that error.
Sometimes even the valid options are not read out. This mostly happens with the first valid option in the list i.e. in the example 'Red'
This is working 100% correct with NVDA.
Any ideas?
Please add aria-label="yourOptionText" attribute to your option tag.
for e.g. aria-label="White Invalid".
Hope this will help.

How do i make Selenium pull out the sidebar menu tree

I have a iframe-sidebar which appears as soon as a widget is hovered over , since it uses the onchange javascript event, and hides back when the sidebar is clicked again. There is a listbox in this sidebar which needs to be clicked for my chain to continue. How do i program Selenium webdriver in Python to pull out this sidebar ?
Thanks
On reading answers to question, I added this :-
element = driver.find_element_by_xpath('//*[#id="leftSiderBarForm:moduleMenu"]')
element = driver.find_element_by_id("leftSiderBarForm:moduleMenu")
hover = ActionChains(driver).move_to_element(element)
hover.perform()
but get error :-
MoveTargetOutOfBoundsException: Message: u'Offset within element cannot be scrolled into view: (72.5, 8.5): [object XrayWrapper [object HTMLSelectElement]]' ;
This is the HTML of that element that i copied from Chrome. I changed actual values to ABC and so on.
<select id="leftSiderBarForm:moduleMenu" name="leftSiderBarForm:moduleMenu" class="comboboxnowidth leftSideMenuSelect " size="1" onchange="jQuery('.submitMenuSelection').click()" style="z-index: 0;"> <option value="">-- Select --</option>
<option value="ABC">abc</option>
<option value="DEF">def</option>
Could i use Javascript to trigger that Jquery ?
from selenium.webdriver.common.action_chains import ActionChains
def hover_over_item(self):
driver = webdriver_connection.connection
element = driver.find_element_by_id(locator)
hover = ActionChains(driver).move_to_element(element)
hover.perform()
Reference

The driver is not unable to locate the element defaultCurrency by xpath.!

The driver is not unable to locate the element defaultCurrency by xpath.
Error -"org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with."
Code:
driver.findElement(By.xpath("//[#id='currency']/fieldset[2]/table/tbody/tr[1]/td[2]")).click();
WebElement defaultCurrency = driver.findElement(By.xpath(".//*[#id='defaultCurrency']"));
Select defaultCurrency_Select = new Select(defaultCurrency); defaultCurrency_Select.selectByVisibleText("USD");
Source Code:
<td>
<select id="defaultCurrency" class="validate[required]" onchange="javascript:clrErrors()" style="height:25px;width:160px;" name="defCurrency.defaultCurrency">
<option value="">Select Currency..</option>
<option value="INR">GBP</option>
<option value="EUR">EUR</option>
<option value="USD">USD</option>
</select>
</td>
WebDriver throw ElementNotVisibleException exception only when element is not visibile. Therefore, have a look at the element, (e.g. via Firebug) and note which element is activating him as to be visible. Then try to activate the first element, and then operate on desired one. Or maybe element is designed to be invisibile at that specific moment, so you should not be allowed to perform actions on it.
Use this
Select currency = new Select(driver.findElement(By.cssSelector("Select[id="defaultCurrency"]")));

Selenium 2 - getting the selected option from drop down list

<select class="selectCity">
<option></option>
<option value="Paris">Paris</option>
<option>New York</option>
<option>London</option>
</select>
Select op1 = new Select(driver.findElement(By.xpath("(//*[#id='cityTable']//*[contains(#class,'selectCity')])")));
List<WebElement> allSelectedOptions = op1.getAllSelectedOptions();
WebElement firstSelectedOption = op1.getFirstSelectedOption();
System.out.println("op1!!!!!"+firstSelectedOption.getText());
The user selected option on the web page is London.
Put the output is op1!!!!!
How to find the option that has been selected on the web page?
Thanks in advance!
Selenium.getSelectedLabel("//string locator");
The above code helps in knowing the option witch is currently selected and visible from the drop down list.
String locator of drop down box can by anything eg:- name,id,xpath
EG : Selenium.getSelectedLabel("name=productIdxSel");

Selenium Webdriver: Select with display none [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Selenium WebDriver - hidden select and anchor
Before I post my question I just want to tell that I am new to Selenium..
I am trying to select an option from a dropdown. The options display when clicked on the down arrow in the dropdown box. But, when checked in the Firebug, the display style was "none" and when trying to select the option using JUnit webdriver code by using click method in Eclipse, it did not work and it gave the exception - "org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with".
Please refer to the attached image for the dropdown and HTML tags.
<select class="size-dropdown mediumSelect selectBox" name="skuAndSize" style="display: none;">
<option value=""></option>
<option value="2545672:S" name="skuId"> S</option>
<option value="2545673:M" name="skuId"> M</option![enter image description here][1]>
<option value="2545674:L" name="skuId"> L</option>
<option value="2545675:XL" name="skuId"> XL</option>
<option value="2545676:XXL" name="skuId"> XXL</option>
<option value="2545677:XXXL" name="skuId"> XXXL</option>
<option value="2545678:XXXXL" name="skuId"> XXXXL</option>
</select>
I looked at this link before posting this question - Selenium WebDriver - hidden select and anchor
But, since I am just starting I am not able to understand clearly.
Note: The same worked in IDE when used clickAt method. But in Webdriver the clickAt method is not present. Can anyone help me in this. Thanks!
Well the matter is Selenium is unable to interact with invisible ( disabled) elemnts. So you need to make element visible. BAsic idea: to make dropdown roll down , then wait with driver.manage.timeout(...) and then click on the appear needed element in dropdown.
Or you can use javascript to click element directly without preceeding dropdown roll down. Js is able to cope with it.
So this approach ALWAYS works:
css1=select[class="size-dropdown mediumSelect selectBox"]>option[value=""]
css2=select[class="size-dropdown mediumSelect selectBox"]>option[value="2545672:S"]
css2=select[class="size-dropdown mediumSelect selectBox"]>option[value="value="2545673:M"]
//.... and so on.....
public void jsClickOn(String cssSelector){
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("var x = $(\'"+cssSelector+"\');");
stringBuilder.append("x.click();");
js.executeScript(stringBuilder.toString());
}
jsClickOn(css1);
jsClickOn(css2);
jsClickOn(css3);
Another way:
using actions builder, advanced user actions API. You can read about it here And code will be smth like that:
WebElement mnuElement;
WebElement submnuElement;
mnEle = driver.findElement(By.Id("mnEle")).click();
sbEle = driver.findElement(By.Id("sbEle")).click();
Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.moveToElement(mnEle).Perform();
// Giving 5 Secs for submenu to be displayed
Thread.sleep(5000L);
// Clicking on the Hidden SubMenu
driver.findElement(By.Id("sbEle")).click();
But also pay attention on the way how you found css selectors, xpaths verifying it in e.g. firepath, addon to firebug in ffox.
Hope this helps you)
See this screen as example of locating dropdown options.