I am trying to get the count of the search results returned in MakeMyTrip application by searching the flights from Hyderabad to Bangalore. By using the below I am able to get the text but how to verify how many number of search results returned.
String output = driver.findElement(By.xpath("//*[#id=\"left-side--wrapper\"]/div[3]")).getText();MakeMyTrip Flight Search
System.out.println(output);
Thanks in Advance
You should use driver.findElements(); method like this below:
// your webelement
By eachSearchElement = By.xpath("//*[#id='left-side--wrapper']/div[3]");
// getting all of available elements on the page and store them in List
List <WebElement> allSearchElements = driver.findElements(eachSearchElement);
// then just simply get the size of particular List above
int howManyElements = allSearchElements.size();
System.out.println("There are " + howManyElements + " present on the page");
Hope this will help.
Related
function myFunction() {
/////////////////////////////////////Fill planning/decor package
var managementSheet = SpreadsheetApp.openById("1P3EF4Edu0efzJVV1Sx-0ayAPaAAiRK8Sl0Y1qZHmcf4");
var packageSheet = managementSheet.getSheetByName("Order Contents");
//Order Contents iterater
var c = packageSheet.getMaxColumns();
var n = packageSheet.getLastRow();
var items = packageSheet.getRange(2,1,n,c).getValues();
var filteredItems = items.filter(function(row) {
if(row[2].toString().includes(firstName +" "+lastName))
{
var results =new Array();
var info = new Array();
info[0]=row[3];
info[1]=row[5];
info[2]=row[9];
info[3]=row[14];
info[4]=row[15];
info[5]=row[16];
results[0]= info;
// result = results.every().valueOf();
Logger.log(results)
var row=22
results.forEach(function(value, index) {
Logger.log("The value at index " + index + " is " + value + ".");
generatedInvoice.getRange(22,1,1,7).setValues([[info[0],,info[1],info[2],info[3],info[4],info[5]]])
row= index + 22+1
})}})
}
Hello. First off, I'm new to appscript/javascript/script in general... Secondly, I'm the worst at explaining things and am so over this as I've been working on it for 2 days with only a few food/water/sleep breaks and just can't figure it out.
I'm trying to take rows from one sheet and copy only some of that row's values to a template...
Customer orders are on one sheet.
Order CONTENTS(for all customers' orders) are on another sheet.
I want to generate an invoice containing everything that the customer has ordered. The code I have currently lists only the final row of the "results" array into my template sheet. I want all of the items that the customer ordered to be added to the invoice. I'm trying to figure out how to use "index" to move to the next line and add the next set of values, but I'm not sure what I'm doing wrong. By logging info, I see that everything is being called correctly and adding to the correct spot in the template. The problem is that it only adds the final line of data into the template when I want all of the lines that match a customer's name.
I am trying to add information from a map received through an http call to a list of objects in Dart. For example, the list of objects are Tools that have the toollocation property:
Tool(
{this.make,
this.model,
this.description,
this.tooltype,
this.toollocation,
this.paymenttype,
this.userid});
I am also using the google distance matrix api to gather the distance from the user that the tool is.
Future<DistanceMatrix> fetchDistances() async {
await getlocation();
latlongdetails = position['latitude'].toString() +
',' +
position['longitude'].toString();
print(latlongdetails);
print('still running');
final apiresponsepc = await http
.get(
'https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=$latlongdetails&destinations=$postcodes&key=xxx');
distanceMatrix =
new DistanceMatrix.fromJson(json.decode(apiresponsepc.body));
return distanceMatrix;
}
What I have been doing in the past is calling a future and just getting the distance once I have returned the original results for the tool. However I want to be able to sort the tool results by distance, so I need to iterate through each tool in the list and add the distance for each of them.
So far I have been trying a foreach loop on the tools list:
finalresults.forEach((tool){ tool.toollocation = distanceMatrix.elements[0].distance.text;});
but clearly this will only add the first distance measurement to every one of the tools.
Is there any way I can iterate through each tool and then add the distance from the distance matrix map? Each distance will be in sequence with each tool in the list.
I think this is what you wanted to do
finalResults.forEach((tool) {
distanceMatrix.elements.forEach((element){
tool.toolLocation = element.distance.text;
});
});
If elements is also a List then you can use the foreach syntax to iterate through it.
I have resolved this with the following code:
int number = 0;
finalresults.forEach((tool) {
tool.toollocation = distanceMatrix.elements[number].distance.text;
number = number + 1;
});
In a process of writing text to PDF, I'm using TextFragment for setting properties of various fields. Instead of setting for each field separately, how do make use of a loop?
My present code:
TextFragment a = new TextFragment("Hi!");
tf.setPosition(dropDown);
tf.getTextState().setFont(new FontRepository().findFont("Arial"));
tf.getTextState().setFontSize(10.0F);
.
.
.
TextFragment n = new TextFragment("n");
tf.setPosition(dropDown);
tf.getTextState().setFont(new FontRepository().findFont("Arial"));
tf.getTextState().setFontSize(10.0F);
I need something like this:
some loop {
.
.
TextFragment txtFrag = new TextFragment(A);
tf.setPosition(dropDown);
tf.getTextState().setFont(new FontRepository().findFont("Arial"));
tf.getTextState().setFontSize(10.0F);
} //This should set properties for all fields
The string in TextFragment("String") is not same for all the fields. It's different for various form fields.
You may simply add text fragments in your PDF file and once you finish adding text, you may get or set different properties for all the text fragments in a PDF file by using the code below:
// Load document
Document document = new Document( dataDir + "input.pdf");
// Create TextAbsorber object to extract all textFragments
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber();
// Accept the absorber for first page of document
document.getPages().accept(textFragmentAbsorber);
// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
// Loop through the Text fragments
for (TextFragment textFragment : (Iterable<TextFragment>) textFragmentCollection) {
// Iterate through text fragments
System.out.println("Text :- " + textFragment.getText());
textFragment.getTextState().setFont(new FontRepository().findFont("Arial"));
textFragment.getTextState().setFontSize(10.0F);
System.out.println("Position :- " + textFragment.getPosition());
System.out.println("XIndent :- " + textFragment.getPosition().getXIndent());
System.out.println("YIndent :- " + textFragment.getPosition().getYIndent());
System.out.println("Font - Name :- " + textFragment.getTextState().getFont().getFontName());
}
// Save generated document
document.save(dataDir + "input_17.12.pdf");
You may visit Working with Text for more information on this. I hope this will be helpful. Please let us know if you need any further assistance.
I work with Aspose as Developer Evangelist.
I had to automate scenario where i get First Name and email address , which i had stored then i need to assert that value with drop down box that its not present.
Here is HTML code for my Page
<select id="Customer" name="Customer" class="valid">
<option value="raj777#gmail.com">123123123 (raj777#gmail.com)</option>
</select>
It contained multiple entries ,
I need to verify that my given text does not exist in it.
I tried this but it does not works
assertNotEquals(fname+" "+em, driver.findElement(By.xpath("//*[#id='Customer']")).getText());
Thanks In Advance !!!
Follow the below process:
Get the text of each element in the dropdown ('option' elements)
Strote the values in a list or array of string.
See the list or array contains your Name & mail id value.
or if u want to assert only, then in for-each loop of the array or list:
Add t
he assert statement in try-catch block.
In catch block, each time execution comes to this block, increase an integer.
After the fr-each loop, check the integer value is equal to yor list or array size.
Code sample for the first scenario:
driver.findElement(By.cssSelector(".trb_outfit_sponsorship_logo_img"))
.click();
System.out.println(dri.findElement(
By.cssSelector(".trb_outfit_sponsorship_logo_img")).getSize());
List<WebElement> dropDownValues = dri.findElements(By
.xpath("//select[#id='Customer']"));
ArrayList<String> dropDownValuesasText = null;
for (WebElement eachValue : dropDownValues) {
dropDownValuesasText.add(eachValue.getText());
}
// boolean result = dropDownValuesasText.contains("Your FirstName & Email value");
//It will pass if your value is present in drop down
assertNotEquals(dropDownValuesasText.contains("Your FirstName & Email value"), true);
I'm really fresh to Python and need help reading information from txt file. I have a large C++ app need to duplicate it in Python. Sadly I have no idea where to start. I've been reading and watching some tutorials, but little help from them and I'm running out of time.
So my task is:
I have a shopping list with:
-Name of the item, price and age.
I also need to create two searches.
Search whether the item is in the shop (comparing strings).
if name of the item is == to the input name.
Search by age. Once the program finds the items, then it needs to print the list according to the price - from the lowest price to the highest.
For example you input age 15 - 30, the program prints out appropriate
items and sorts them by the price.
Any help would be nice. At least from where I could start.
Thank you.
EDITED
So far, I have this code:
class data:
price = 0
agefrom = 0
ageto = 0
name = ''
# File reading
def reading():
with open('toys.txt') as fd:
toyslist = []
lines = fd.readlines()
for line in lines:
information = line.split()
print(information)
"""information2 = {
'price': int(information[1])
'ageftom': int(information[2])
'ageto': int(information[3])
#'name': information[4]
}"""
information2 = data()
information2.price = int(information[0])
information2.agefrom = int(information[1])
information2.ageto = int(information[2])
information2.name = information[3]
toyslist.append(information2)
return toyslist
information = reading()
I HAVE A PROBLEM WITH THIS PART. I want to compare the user's input with the item information in the txt file.
n_search = raw_input(" Please enter the toy you're looking for: ")
def name_search(information):
for data in information:
if data.name == n_search:
print ("We have this toy.")
else:
print ("Sorry, but we don't have this toy.")
If you want to fins something in a list it's generally as straightforward as:
if "apple" in ["tuna", "pencil", "apple"]
However, in your case, the list to search is a list of lists so you need to "project" it somehow. List comprehension is often the easiest to reason about, a sort of for loop in a for loop.
if "apple" in [name for name,price,age in [["tuna",230.0,3],["apple",0.50,1],["pencil",1.50,2]]]
From here you want to start looking at filters whereby you provide a function that determines whether an entry is matched or not. you can roll your own in a for loop or use something more functional like 'itertools'.
Sorting on a list is also easy, just use 'sorted(my_list)' supplying a comparator function if you need it.
Examples as per your comment...
class ShoppingListItem:
def __init__(self,name,price,age):
self.name=name
self.price=price
self.age=age
or
from collections import namedtuple
sli = namedtuple("ShoppingListItem",['name','age','price'])