Cannot locate option dropdown with value in selenium web driver - selenium-webdriver

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOGON_selectedUser")));
WebElement mySelectElement = driver.findElement(By.id("LOGON_selectedUser"));
mySelectElement.click();
Select dropdown= new Select(driver.findElement(By.id("LOGON_selectedUser")));
dropdown.selectByVisibleText("HOTLINE-FAMILY SAFETY - Acting Supervisor");
Below is the error I'm getting:
Cannot locate option with text: HOTLINE-FAMILY SAFETY - Acting Supervisor
I tried with by. value bit no luck. :(
However, I'm able to select the dropdown with statement mySelectElement.click(); but when I try to select the drop-down, I'm keep on getting cannot locate the element. Pls help.
Here is the DOM:
enter image description here

The web page has been built using Angular. Please try to induce Explicit waits with Select class.
Select dropdown = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[#name='selectedUser' and #id='LOGON_selectedUser' and #onchange]"))));
dropdown.selectByIndex(1);
or if that does not work, the below should work
((JavascriptExecutor) driver).executeScript("return document.getElementById('LOGON_selectedUser').selectedIndex = '" + index + "';)
where index is a variable, try to pass index number like 1,2,3 and so on...

Related

I want to locate an element in linkedin DOM for add new education section (plus sign)

I want to find the Xpath of (plus sign) in linkedin profile in adding new education field as per screenshot
driver.findElement(By.xpath(".//*[contains(#aria-label,'Add new education')]")).click();
but an error massage found that:
Unable to locate element
Try with the below xpath.
driver.findElement(By.xpath(".//li-icon[#aria-label ='Add new education']")).click();
Note: if you are still not able to locate the element then probably you are trying to access the webelement even before it is loaded on the webpage.
In that case you need to use
//30 is the wait time in seconds.
WebDriverWait wait = new WebDriverWait(driver,30);
//This will wait for 30 seconds to locate the element before throwing an Exception.
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//li-icon[#aria-label ='Add new education']")));
Let me know if this works.
Welcome to SO. Here is the locator to identify the + in education.
Using CSS a[class$='add-education ember-view']
driver.findElement(By.cssSelector("a[class$='add-education ember-view']")).click();
xpath //a[contains(#class,'add-education ember-view')]
driver.findElement(By.xpath("//a[contains(#class,'add-education ember-view')]")).click();

viewcriteria is not working for data having word "and"

i am working with applying view criteria programaticlly, till now it was fine, but when i searched with "develop and unit test" it is showing 0 records even though my table having data. iam using like operator. could any one help on this .
i have one table, having option to filter by providing select combo box list of vales, for every column when i select any thing in lov in value change listener i am applying viewcriteria programatically on table vo.
note. every thing is programatic view object only there is no point of entity, or sql
Sample Code:
DCIteratorBinding bindIterator = ADFUtils.findIterator("Tri2EWS_ETKAPIData_VO1Iterator");//Table viewObject(programatic)
Tri2EWS_ETKAPIData_VOImpl voimpl = (Tri2EWS_ETKAPIData_VOImpl) bindIterator.getViewObject();
ViewCriteria viewCriteria = voimpl.createViewCriteria();
viewCriteria.setName("MyVc");
ViewCriteriaRow viewCriteriaRow = viewCriteria.createViewCriteriaRow();
viewCriteriaRow.setOperator("ViewAttr1", "LIKE");
viewCriteriaRow.setAttribute("ViewAttr1", "stack and OverFlow");
viewCriteria.add(viewCriteriaRow);
viewCriteria.setCriteriaMode(ViewCriteria.CRITERIA_MODE_CACHE);
voimpl.applyViewCriteria(viewCriteria, true);
voimpl.executeQuery();
voipmpl.getRowCount();//Getting 0 here (Actually i should get 1)
Turn on debug messages for ADF BC (jbo.debugoutput) so you can see the SQL that is being generated.
This will help you figure out if the query is correctly formatted.

Displaying Parse Data to ContainerList

I want to display data from Parse in a list from GamesScores class using Container in Codename One, this is what I've tried so far and it's not showing anything nor giving any errors:
Container container = findListCont();
container.setLayout(BoxLayout.y());
container.setScrollableY(true);
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
List<ParseObject> results = (List<ParseObject>) query.find();
System.out.println("Size: " + results.size());
container.addComponent(results, f);
Please help me out, I'm a new in Codename One. If there tutorials on it, please share or anything to help me achieve the desired results.
I'm actually shocked this isn't failing. You are using the add constraint to place the object result as a constraint and you add the form object into the container...
You need to loop over the results and convert them to components to add into the layout. It also seems that you are using the old GUI builder which I would recommend against.
Generally something like this rough pseudo code should work assuming you are using a box Y layout:
for(ParseObject o : results) {
MultiButton mb = new MultiButton(o.getDisplayValue());
f.add(mb);
}
f.revalidate();

Clear field and type in selenium webdriver

I have a qty field in code nead to clear '1' and type 2 but below code is inserting '21'. Qty.clear is clearing the field but Qty.sendkeys is inserting '21'
The field will be like this
Quantity= - 1 +
WebElement Qty=driver.findElement(By.cssSelector("#quantity_11046"));
Qty.clear();
Qty.sendKeys("2")
I don't understand why this not works for you but I can suggest try other method using CTRL A (select) and then insert the value. Something like
Qty.sendKeys(Keys.chord(Keys.CONTROL, "a"), "2"))

sendKeys(Keys.TAB) not working in JMeter Webdriver Sampler

I am trying to enter a value into a textfield then Tab to the next field (which also enters the value). The Keys.TAB method does not seem to be working.
My code is as follows:
var Keys = JavaImporter(org.openqa.selenium.Keys)
var input = WDS.browser.findElement(pkg.By.xpath('xpath_to_input'))
input.sendKeys('value')
input.sendKeys(Keys.TAB)
I am getting the following error:
sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method org.openqa.selenium.remote.RemoteWebElement.sendKeys(string). <Unknown source>
Thank you for your help. I have tried all sorts of things and it will not work.
In addition to what ekuusela suggests there are 2 more options:
Use \t escape sequence like:
input.sendKeys('value\t');
Use java.awt.Robot approach as follows:
input.sendKeys('value')
var robot = new java.awt.Robot()
var keyEvent = java.awt.event.KeyEvent
robot.keyPress(keyEvent.VK_TAB)
robot.keyRelease(keyEvent.VK_TAB)
Remember that "Robot" approach simulates native key and mouse event on the machine where it is executed so if you use remote webdriver instance it won't play.
For more WebDriver Sampler tips and tricks see The WebDriver Sampler: Your Top 10 Questions Answered guide.
If you use Java 6 you must pass the string in an array, like this:
var input = WDS.browser.findElement(pkg.By.xpath('xpath_to_input'))
input.sendKeys(['value'])
input.sendKeys([Keys.TAB])
http://jmeter-plugins.org/wiki/WebDriverSampler/

Resources