Xpath to locate the element of a day from the date picker - selenium

I have to click on day 11 on the calendar but I am unable to construct XPath to perform click operation on that particular date.
I am unable to copy-paste the HTML code here so kindly find the attached image for the HTML and please suggest suitable XPath.

If you need to click on the active day, which is 11 in this case, you can fetch it using its class in the xpath.
Your should be:
//td[#class='active day']

Try this:
CODE
day_that_you_want = "10"
//td[contains(text(), day_that_you_want)]

Related

How to uniquely identify Date and Time selector in a scenario where more than one DateTime Pickers shows the same XPATH?

How to uniquely identify Date and Time selector in a scenario where more than one DateTime Pickers (StartDate and EndDate) shows the same XPATH?
For example,
XPath of Select Date in Start Date(UTC) :
/html/body/div[3]/div1/div/div1/span1/div/input
XPath of Select Date in End Date(UTC) :
/html/body/div[3]/div1/div/div1/span1/div/input
As you can see, both (Start Date and End Date) have same XPATH, but using these XPATH automation via selenium not feasible
snapshot of DateTime Pickers on the same webpage
How to uniquely identify these controls so that it can be automated via Selenium?
Modern web applications modify the DOM a lot to achieve the desired experience.
The actual XPath depends on the click path since the behavior influences the shape of the DOM. On the first click to the startDate, the XPath is
/html/body/div[2]/div[1]/div/div[1]/span[1]/div/input
since the UI library will add the div when the input field is clicked.
When the end Date input field is clicked, another div is created for the popover for end date. This will then be:
/html/body/div[3]/div[1]/div/div[1]/span[1]/div/input
Look for some attributes in DOM corresponding to date-picker element, which makes them unique. If there are such attributes available, you can use them to identify controls uniquely like this
/html/body/div[3]/div1/div/div1/span1/div/input[#attributeName='attributeValue']
In case, there is no unique attributes available and both the date picker control is available, then you can use index to get first and second element using
First element:
/html/body/div[3]/div1/div/div1/span1/div//input[1]
Second element
/html/body/div[3]/div1/div/div1/span1/div//input[2]

How to get XPath of an element when it is in sub tab (Salesforce Lightning component)

In the following snippets, XPath for the drop down element in last column of accounts table is similar in Subtab and Main page.
I am using the XPath expression
//table/tbody/tr[2]/td[10]/span/div/a[2][#role="button"]
to click on drop down element. But unable to do so as it happens to appear in the previous page too.
Please help me in identifying unique irrespective of tabs.
You can use this XPATH :- (//table/tbody/tr[2]/td[10]/span/div/a[2][#role="button"])[1]

How to select value from Google auto location using Selenium

How to automate this to select particular value even the dropdown list id cannot be inspected. Can anyone help me out on this?
Need to select U.S. 22 Imperial from the list
Please find the HTML snippet
I am unable to proceed more than this. Please help me out!
WebElement location = driver.findElement(By.id("selectbox-city-list2"));
location.sendKeys("us");
You could use sendKeys and send arrow down to select an option. Selecting one by one with the arrow down will highlight the value. You will be able to check the highlighted value using the CSS class of highlighting.
You can use ActionClass
using this you can move your cursor over a specific element based on coordinates and perform a click.
1.So taking the coordinates of that text box.
2.Enter the full value in the text box. ,
3.calculate a very near coordinate to that text box(so that it will be the suggestion) and perform a click.
element = xxxxxxx;
Actions builder = new Actions(driver);
builder.moveToElement(element, x_coord, y_coord).click().build.perform();

How select date in calendar with Selenium?

Here is the html for calendar. How to select date using css selector, xpath or something else.
http://wklej.org/id/2772453/ - FIRST CLICK ON CALENDAR
http://wklej.org/id/2772455/ - SECOND CLICK ON CALENDAR
ClickElementById("ctl00_ctl00_ctl00_ContentPlaceHolderCenter_ContentPlaceHolderBody_ContentPlaceHolderBody_dfSalesAgrementData_imgSetDate");
ClickElementByCssSelector("td:contains('Dzisiaj')");
This works. But if i try to click on calendar again and select date this does not work. Only first time date selection works. I cant change date.
I have this. But that works only once too.
ClickElementById("ctl00_MainContentPlaceHolder_dFieldContractEndDate_imgSetDate");
ClickElementByXPath("html/body/div[1]/table/tbody/tr[4]/td[4]");
Your question is a bit hard to understand and based on my understanding, can you please try this?
ClickElementByCssSelector("td[class='day selected today']");

Selenium WebDriver and xpath locating inside WebElement

I have a page containing multiple forms with their own submit buttons and other elements. While testing the page, I locate the second form
WebElement form = getDriver().findElement(By.id("form2"));
and then field and submit button
form.findElement(By.name("text")).sendKeys("Adding some text here");
form.findElement(By.xpath("//input[#type='submit']")).click();
However these xpath locations take effect on the first form. Is it really so that the xpath doesn't work inside a specified element?
Try a relative path:
form.findElement(By.xpath(".//input[#type='submit']")).click();
In fact Selenium works with the first found by xpath element. If you know exact order number you can add such a number to your xpath //input[#type='submit'][2]. Please note that numbering in xpath starts from 1 but not 0. So given xpath will found for you the second input with #type='submit'.