This is my scenario:
create an id. (ID has a timestamp on it for the purpose of regression testing). For example abc_201502125566781. In other words, a unique id is created each time.
go to a different screen, select the same id in the pulldown menu, that was created in step 1. (Manual testing confirms that the id is available in the pulldown menu from step 1)
The following code works(not really), because it creates the new id in the search field, and grabs it, rather than the id from step 1 above. How can I tell the driver to grab the ID that was created in step 1. Thanks!
NOTE: domain_id has a timestamp assigned to it.
public static String domain_id = PropertyLoader.loadProperty("PVT_DOMAIN_ID") + now;
My code:
WebDriverWait wait = new WebDriverWait(driver, 60);
By xpath = By.xpath("//div[#id='overview_form']//select/option");
WebElement element = new WebDriverWait(driver,10).until(ExpectedConditions.presenceOfElementLocated(xpath));
element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//option[.='" + domain_id + "']")));
String getThePreviouslyCreatedsiteId = element.getText().trim();
driver.findElement(By.xpath(PvtConstants.ADD_PAGE_SITES_PULLDOWN_SEARCH_FIELD)).sendKeys(getThePreviouslyCreatedsiteId);
driver.findElement(By.xpath(PvtConstants.ADD_PAGE_SITES_PULLDOWN_SEARCH_FIELD)).sendKeys(Keys.ENTER);
STEP 1:
/*1. From Left Navigation bar, select Setup > Sites*/
setup.setUp();
siteClickFromLeftHandMenu();
/*2. Click the +Add button*/
clickToAddNewSiteButton();
/*3. On Add/Edit Site screen, enter a valid Site ID (i.e. Site_timestamp) and click Add.*/
driver.findElement(By.xpath(PvtConstants.ADD_SITE_ID)).sendKeys(site_id);
verifyDisplay(site_id + "", By.xpath(PvtConstants.ADD_SITE_ID));
/*4. Enter the same value as domain.*/
driver.findElement(By.xpath(PvtConstants.ADD_SITE_DOMAIN)).sendKeys(domain_id);
verifyDisplay(domain_id + "", By.xpath(PvtConstants.ADD_SITE_DOMAIN));
driver.findElement(By.xpath(PvtConstants.ADD_SITE_DOMAIN)).getText();
//click to add the site
clickAddToAddSiteInTheAccount();
/*5. The message "Successfully Added" is displayed.*/
verifyDisplay("Successfully added.", By.id(PvtConstants.ADD_SITE_SUCCESSFULLY_ADDED_MESSSAGE));
Related
I have 3 elements with a particular instance (eg.: there are 3 <div class="sc-1xo2hia-0 TegxE"> under each <div direction="vertical" class="sc-1fp9csv-0 iFnncD"> in the webiste: https://www.blockchain.com/btc/block/00000000000000000004b91bad9ecfa8c0e57c256d0007cca6f0a2a9e54a2ccc ; click 'Inspect element' on the first transaction to view the specific DOM tree)
Now I want to access the some elements from 2nd and 3rd instance of the first tag (sc-1xo2hia-0 TegxE)
How do I do this efficiently?
PS: This code :
from selenium import webdriver
driver=webdriver.Firefox()
driver.get('https://www.blockchain.com/btc/block/00000000000000000004b91bad9ecfa8c0e57c256d0007cca6f0a2a9e54a2ccc')
Txn_elements=driver.find_elements_by_xpath('//div[#class="sc-1fp9csv-0 iFnncD"]')
length=len(Txn_elements)
for i in range(0,length):
element=Txn_elements[i]
data=element.find_elements_by_xpath(".//div[#class='sc-1xo2hia-0 TegxE'][1]")
print data[0].text
still prints details of the 0th <div class="sc-1xo2hia-0 TegxE"> only
i.e. it still prints:
Hash
fc1630ec40d95da3fcca40d499c4be616ea6591dda6f0d3d85a678d47c91ae62
2019-11-06 8:37 PM
where as it should have printed:
17A16QmavnUfCW11DAApiJxp7ARnxN5pGX
2.62352930 BTC
xpath= (.//div[#class='ge5wha-0 bLrlXr']/a)[1] //to get 17A16QmavnUfCW11DAApiJxp7ARnxN5pGX
xpath = (.//div[#class='ge5wha-1 bWdiuU']/span)[1] //to get 2.62352930 BTC
try with this xpath.
Please check below solution its working but I am not sure why you are using for loop if you just want to print two elements in the //div[#class="sc-1fp9csv-0 iFnncD"]
if you want to print only one then remove for loop and try to execute your code
driver.get('https://www.blockchain.com/btc/block/00000000000000000004b91bad9ecfa8c0e57c256d0007cca6f0a2a9e54a2ccc')
Txn_elements=driver.find_elements_by_xpath('//div[#class="sc-1fp9csv-0 iFnncD"]')
length=len(Txn_elements)
for i in range(0,length):
element=Txn_elements[i]
data=element.find_elements_by_xpath("//body/div[#id='__next']/div[#class='sc-1myx216-0 iygrgv']/div[#class='p5q4id-0 fasJHc sc-5vnaz6-1 doVOgS']/div[#class='fieq4h-0 klQmUt']/div[#class='xoxfsb-0 bmukdK']/div[3]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/a[1]")
print data[0].text
data1 = element.find_elements_by_xpath(
" //body/div[#id='__next']/div[#class='sc-1myx216-0 iygrgv']/div[#class='p5q4id-0 fasJHc sc-5vnaz6-1 doVOgS']/div[#class='fieq4h-0 klQmUt']/div[#class='xoxfsb-0 bmukdK']/div[3]/div[2]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/span")
print data1[0].text
Try below the solution for transaction ID
driver.get('https://www.blockchain.com/btc/block/00000000000000000004b91bad9ecfa8c0e57c256d0007cca6f0a2a9e54a2ccc')
List1 = driver.find_elements_by_xpath("//body/div[#id='__next']/div[#class='sc-1myx216-0 iygrgv']/div[#class='p5q4id-0 fasJHc sc-5vnaz6-1 doVOgS']/div[#class='fieq4h-0 klQmUt']/div[#class='xoxfsb-0 bmukdK']/div[*]/div[2]/div[1]/div[2]/div/div/div/a")
for items in List1:
print (items.text)
List2 = driver.find_elements_by_xpath("//body/div[#id='__next']/div[#class='sc-1myx216-0 iygrgv']/div[#class='p5q4id-0 fasJHc sc-5vnaz6-1 doVOgS']/div[#class='fieq4h-0 klQmUt']/div[#class='xoxfsb-0 bmukdK']/div[*]/div[2]/div[1]/div[2]/div/div/div/div/span")
for items in List2:
print (items.text)
I'm new to automation with selenium webdriver. I'm trying to book a flight on a travel website. (ryanair.com)
I'm getting stuck with a popup datepicker. I can use .sendkeys to enter the day only, after any field on the date inputs is clicked it triggers the popup calendar to appear so if the format of the inputis dd/mm/yyyy and I want to enter "20042019" it only enters 20 in the dd and then automatically selects the current month and year as autocomplete and opens the calendar popup.
I'ver read a few articles saying that these calendars are usually of two types
1. iframe
2. datepicker - I think the one on ryanair is datepickers based on the xpath below
//div[#id='datetimepicker_dateview']//table//tbody//td[not(contains(#class,'k-other-month')
Maybe that's the wrong xpath? But I think it's correct
I have tried to find the list of dates to book using :
List<WebElement> list_AllDateToBook = driver.findElements(By.xpath()
System.out.println("size of list is : " + list_AllDateToBook.size() );
System.out.println("list is : " + list_AllDateToBook );
Output is:
size of list is : 0
list is : []
When I use xpath to enter the date of the date field it works for the first input using:
WebElement day = driver.findElement(By.xpath("//*[#id='row-dates-pax']/div[1]/div/div[1]/div/div[2]/div[2]/div/input[1]"));
However when I change the xpath to the second input it won't enter the second input(month)
WebElement day = driver.findElement(By.xpath("//*[#id='row-dates-pax']/div[1]/div/div[1]/div/div[2]/div[2]/div/input[2]"));
A sample of the datepicker HTML is below (it's too long to add it all!)
<core-datepicker class="start-date" default-date="" start-date="18-03-2019" end-date="28-03-2020" highlight-from="20-03-2019" highlight-to="20-04-2019" end-show="true" fly-out="true" value="dateRange.startDate" cb-event-id="cal-selector:select-start-date" unavailable-dates="dateRange.unavailabiltyStartDates" selected-month-view="dateRange.startDateSelectedMonthView" show-month-toggle="::dateRange.showMonthToggle" show-single-month=""><!----><div ng-class="::{'has-monthly-toggle': isMonthToggleVisible()}"><div bindonce="" class="datepicker-wrapper r scrollable value-selected" ng-class="{ scrollable: !device.isPhone(), mobile: device.isPhone(), 'value-selected': value, 'six-rows': checkIf6Rows()}" style="transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1); transition-duration: 0ms; transform: translate(0px, 0px) translateZ(0px);"><!----><!----><ul ng-if="!device.isPhone()"><!----><li bindonce="" ng-repeat="i in _monthViews" ng-class="{ 'starting-month': checkIfIsSame(getDate(i), highlightFrom, 'month'), 'selected-month': checkIfIsSame(getDate(i), value, 'month'), 'highlight-on': canHighlight(i) }" class="calendar-view starting-month selected-month"><h1 class="month-name">March 2019</h1><ul class="week-days"><!---->
I'm really stuck here. Any advice would be great.
Thanks
Here is the working code from python. Please see the approach that I followed and simulate the same in java.
import os
import time
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
def get_full_path_to_folder(folderName):
folders = os.path.abspath(os.pardir).split(os.sep)
folderPath = ''
for folder in folders:
if folderPath == '':
folderPath = folder
else:
folderPath = folderPath + "\\" +folder
if os.path.isdir(os.path.join(folderPath, folderName)):
return os.path.join(folderPath, folderName)
break
def wait_for_element_present(locator_type, locator):
if locator_type == 'xpath':
return (wait.until(EC.presence_of_element_located((By.XPATH, locator))))
elif locator_type == "css":
return (wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, locator))))
chrome_options = ChromeOptions()
chrome_options.add_argument("--incognito")
driver = webdriver.Chrome(executable_path=os.path.join(get_full_path_to_folder('drivers'), "chromedriver.exe"))
driver.implicitly_wait(10)
wait = WebDriverWait(driver,10)
url = "https://www.ryanair.com/us/en/"
# go to url
driver.get(url)
#================ you should focus the below code=======================
# close the cookie pop up, otherwise the date and country elements not interable for selenium for interaction
wait_for_element_present('css',".cookie-popup__close").click()
#click on destination edit box
driver.find_element_by_css_selector(".route-selector-destination").click()
# select desitnation country
destiCountry = wait_for_element_present('xpath',"//div[#ng-repeat='option in $ctrl.firstOptions track by option.id' and text()=' Italy']")
destiCountry.click()
#select destination airport
desti = wait_for_element_present('xpath',"//span[contains(#ng-if,'secondOptionsEnabled') and .='Naples']")
desti.click()
# select outbound date
dateEle = wait_for_element_present('css',"li[data-id='24-03-2019']")
if dateEle.value_of_css_property('font-size') == '15px':
dateEle.click()
#select in bound date
dateEle = wait_for_element_present('css',"li[data-id='20-04-2019']")
if dateEle.value_of_css_property('font-size') == '15px':
dateEle.click()
#hurry, the date selection is successful.
Please try with :
li[data-id='12-04-2019'] span
Note: Add till span tag. Just tried via console and working.
document.querySelector("li[data-id='12-04-2019'] span").click()
Suppose I have a HTML that have some heading & text like:
Heading 1
text......
Heading 2
text.....
Heading 3
text.....
Now I have to print this template in PDF, during print out, I have to add index page which actually refer page number with heading. Means print out should be like this.
Heading 1 ....... 1 [page number]
Heading 2 ....... 2
Heading 3 ....... 3
Heading 1
text......
Heading 2
text.....
Heading 3
text.....
So here I want to know, how to know page number based on text in HTML, like heading 1 belong to which page number & for others.
Any suggestion or idea really appreciated.
pdfConverter.PdfFooterOptions.PageNumberTextFontSize = 10;
pdfConverter.PdfFooterOptions.ShowPageNumber = true;
Its done inside the body of this method :-
private void AddFooter(PdfConverter pdfConverter)
{
string thisPageURL = HttpContext.Current.Request.Url.AbsoluteUri;
string headerAndFooterHtmlUrl = thisPageURL.Substring(0, thisPageURL.LastIndexOf('/')) + "/HeaderAndFooterHtml.htm";
//enable footer
pdfConverter.PdfDocumentOptions.ShowFooter = true;
// set the footer height in points
pdfConverter.PdfFooterOptions.FooterHeight = 60;
//write the page number
pdfConverter.PdfFooterOptions.TextArea = new TextArea(0, 30, "This is page &p; of &P; ",
new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10, System.Drawing.GraphicsUnit.Point));
pdfConverter.PdfFooterOptions.TextArea.EmbedTextFont = true;
pdfConverter.PdfFooterOptions.TextArea.TextAlign = HorizontalTextAlign.Right;
// set the footer HTML area
pdfConverter.PdfFooterOptions.HtmlToPdfArea = new HtmlToPdfArea(headerAndFooterHtmlUrl);
pdfConverter.PdfFooterOptions.HtmlToPdfArea.EmbedFonts = cbEmbedFonts.Checked;
}
See this page for more details
http://www.expertpdf.net/expertpdf-html-to-pdf-converter-headers-and-footers/
This is actually a pretty tricky problem which ExpertPDF would have to provide specific functionality to make possible.
My solution (not expertpdf) for this was to calculate the layout of the PDF first, get the text to be used in the index for each page and then calculate the layout of the index page/s. Then I'm able to number the pages (including the index pages) then update the page numbers in the index.. This is the only way to handle template pages which span multiple pages themselves, index text which wraps to take up more than a single line, and indexes which span multiple pages.
Create a TextElement
TextElement te = new TextElement(xPos, yPos, width, ""Page &p; of &P;"", footerFont);
footerTemplate.AddElement(te);
The library will automatically replace the &p; tokens.
I wanted to have a submenu manually append to a submenu("History") under "Edit"
wxMenuBar * menubara = GetMenuBar();
wxMenu * menua = menubara->GetMenu(1);
wxInt32 menuIda = menua->FindItem(wxT("History"));
wxMenuItem * menuItema = menua->FindItem(menuIda);
This is how I get History as a wxMenuItem. However, there is no addSubMenu for wxMenuItem. How can I add a submenu to History?
From my memory, so I might be wrong: you have to create another menu (if it does not already have it, get it with GetSubMenu), insert a new menu item for the new entry and use wxMenuItem->SetSubMenu to set it.
How can I get the all element id's of a screen in selenium?
Please refer to this screenshot
Element ID is getting changed every time the page loads. I used contains#id , start-with#id, but it doesn't work every time. Now I want to get all the element id's from the webpage, so I can select the exact element.
My webpage contains input text, buttons, drop-downs.
Use Xpath instead or cssSelector. If you persist on knowing all page ids as a list of String in java, try to execute a javascript function.
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// Go to the Google Suggest home page
driver.get("http://www.google.com/webhp?complete=1&hl=en");
ArrayList ids = (ArrayList)((JavascriptExecutor) driver).executeScript(
" var allElements = document.getElementsByTagName('*'); var allIds = []; "
+ " for (var i = 0, n = allElements.length; i < n; ++i) { "
+ " var el = allElements[i]; "
+ " if (el.id) { allIds.push(el.id); } } return allIds; "
);
Regards,
Alan Mehio
London, UK