I am unable to select an item if there is only 1 result showing(see image 1). If there are 2 results, desired item can be selected(see image 2). It just proceeds to the next scenario which inputs the date. it inputs the dates in the search bar instead of the date field. but works perfectly when there are 2 results.
Image 1
image 1
Image 2
image 2
Here is my code:
java.util.List<WebElement> substituterlist = getDriver.findElements(By.xpath("//*[#id='select2-drop']/ul/li"));
int list = substituterlist.size();
for (int i = 1; i <= list; i++) {
WebElement subUser = getDriver.findElement(By.xpath("//*[#id='select2-drop']/ul/li[" + i + "]/div"));
String subUsername = subUser.getText();
System.out.println(subUsername.indexOf("-"));
String selectUsr = subUsername.substring(0, subUsername.indexOf("-") - 1);
if (substituteUser.equals(selectUsr)) {
waitForMoreTime(10);
subUser.click();
Related
I am trying to set values in a matrix combobox but I cannot be able to set the first value of date to that combobox. It shows blank and when I select a date, it does not fill the field anyway.
The values I get from the DB are as follows:
Here is my code below including binding the combobox field to a userdatasource:
_expDate = _form.DataSources.UserDataSources.Add("iV_15", SAPbouiCOM.BoDataType.dt_DATE, 100);
oIColumns = oIMatrix.Columns;
_colExpDate = oIColumns.Item("iV_15");
_colExpDate.DataBind.SetBound(true, "", "iV_15");
The below code runs when there is a lost focus change event to the item selection field:
#region Item Change Event Expiry dates
_cmbExpDate = (SAPbouiCOM.ComboBox)oIMatrix.Columns.Item("iV_15").Cells.Item(pVal.Row).Specific;
int count = _cmbExpDate.ValidValues.Count;
if (count > 0)
{
_expDate.ValueEx = "";
for (int j = 0; j <= count - 1; j++)
_cmbExpDate.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index);
}
var expDates = (from oi in _db.OITMs
join ob in _db.OBTNs
on oi.ItemCode equals ob.ItemCode
where ob.ItemCode == _itemNo.ValueEx && oi.OnHand > 0
orderby ob.ExpDate
select new
{
ExpDate = ob.ExpDate
}).Distinct().ToList();
if (expDates.Count > 0)
{
foreach (var item in expDates)
_cmbExpDate.ValidValues.Add(item.ExpDate?.ToString(), item.ExpDate?.ToString());
_cmbExpDate.Select(0, SAPbouiCOM.BoSearchKey.psk_Index);
_expDate.ValueEx = _cmbExpDate.Value;
}
#endregion
What could be wrong. Is there a better way to achieve what I need in SAP B1?
as a test try a different data type for your:
_expDate = _form.DataSources.UserDataSources.Add("iV_15", SAPbouiCOM.BoDataType.dt_DATE, 100);
test it with: SAPbouiCOM.BoDataType.dt_LONG_TEXT
you can also try just selecting the value on the combo, instead of setting uds as well.
My aim is to add the different drop down value 3 times in the script.
By using for I am able to select and add the same value 3 times but want to select and add the different drop down value every time.
Right now i am able add the same skill three times but i want to add three.
Please suggest how can different value every time the loop executes
here is the code which i am using right now.
for(int i=0; i<=2; i++){
Select skill = new Select(m1.findElement(By.xpath(".//select[#id='skill']")));
skill.selectByValue(skills);
Select proficiency = new Select(m1.findElement(By.xpath(".//select[#name='proficiency']")));
proficiency.selectByValue("3");
m1.findElement(By.xpath(".//button[#id='addskill']")).click();
Thread.sleep(2000);
If you want add diffrent dropdown value 3 times use dropdown.selectByIndex(index).
Select skill = new Select(m1.findElement(By.xpath(".//select[#id='skill']")));
Select proficiency = new Select(m1.findElement(By.xpath(".//select[#name='proficiency']")));
for(int i = 1; i <= 3; i++){
skill.selectByIndex(i);
proficiency.selectByIndex(i);
m1.findElement(By.xpath(".//button[#id='addskill']")).click();
Thread.sleep(2000);
}
OR
For random value selection in the drop down items.You need know how many items are their in the dropdown first.
Select skill = new Select(m1.findElement(By.xpath(".//select[#id='skill']")));
List<WebElement> listOptionDropdown = skill.getOptions();
int dropdownCount = listOptionDropdown.size();
Select proficiency = new Select(m1.findElement(By.xpath(".//select[#name='proficiency']")));
List<WebElement> listOptionDropdown1 = skill.getOptions();
int dropdownCount1 = listOptionDropdown1.size();
for(int i = 1; i <= 3; i++){
int random = (int)(Math.random());
random = random*dropdownCount +1;
skill.selectByIndex(random);
int random1 = (int)(Math.random());
random1 = random1*dropdownCount1 +1;
proficiency.selectByIndex(random1);
m1.findElement(By.xpath(".//button[#id='addskill']")).click();
Thread.sleep(2000);
}
How to get all data from the webpage without using scroll or page up and down.
int n = 10;
for (int i = 0; i < n; i++) {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#type=\"text\"]")));
List<WebElement> FV = driver.findElements(By.xpath("//*[#type=\"text\"]"));
WebElement aa = FV.get(i);
String cc = aa.getAttribute("value");
System.out.println(cc);
After I run this code it displays blank.
[![enter image description here][1]][1]
in image the numbering is not in sequence order, I need to verify if no are in sequence 1, 2, 3 , 4 then test case pass else fail.
Social Networking URL #1:
text box
Social Networking URL #2:
text box
Social Networking URL #1:
textbox
Social Networking URL #1:
text box
To verify Numbering should go 1,2,3,4
please help, they are not allowing me to attach image for more clearance
You can get the all elements by driver.find_elements_by_css_selector(css_selector) with the given css_selector then you can get it text by .text finally check if the number is increasing sequencially:
Python:
def check_if_sequencial(css_selector):
result = True
elms = driver.find_elements_by_css_selector(css_selector)
for i in xrange(len(elms) - 1):
text1 = elms[i].text
text2 = elms[i+1].text
# slicing after dash to end of string, convert to int
number1 = int(text1[text1.index("#")+1 : len(text1)])
number2 = int(text1[text2.index("#")+1 : len(text2)])
if number2 != number1 + 1:
print "number1: %d and number2: %d are not sequencial" %(number1, number2)
result = False
break
return result
Java:
public boolean check_if_sequencial(String css_selector){
boolean result = true;
List elms = driver.findElements(By.cssSelector(css_selector));
for (int i = 0; i < elms.length - 1; i++) {
String text1 = elms[i].text;
String text2 = elms[i+1].text;
# spliting by dash take the second, convert to int
String[] parts1 = text1.split("#");
int number1 = Integer.parseInt(parts1[1]);
String[] parts2 = text2.split("#");
int number2 = Integer.parseInt(parts2[1]);
if (number2 != number1 + 1){
System.out.println("number1: " + number1 + " and number2: " + number2 + " are not sequencial");
result = false;
break;
}
}
return result;
}
I want to check the number of characters I can insert in a text field, and was thinking of using 'for loop' but it would not help as Selenium tries to insert more than required character the field will not accept but test goes on without any failure, so is there a way to get character count of the text field?
Would this work?
final String myLongString = "Something horrrrribly looooong";
final int longStringLength = myLongString.length();
// assuming driver is a healthy WebDriver instance
WebElement elem = driver.findElement(By.id("myInput"));
elem.sendKeys(myLongString);
// it's possible that you'll first need to lose focus on elem before the next line
int realLength = elem.getValue().length();
assertEquals(longStringLength, realLength);
Using Protractor I captured the actual text in the field and then did a forloop to count each letter.
element(by.css('elementPATH')).getAttribute('value').then(function(words){
//forloop to count each word
var x = 0
for(var i = 0; i < words.length; i++) {
x = x + 1;
};
//check condition
expect(x).toBe(200);
return true;
});
Let me know if this helps.