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

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]

Related

Selenium XPath for WebTable using parent & sibling

I am trying to automate the web table on the demoqa site https://demoqa.com/webtables where I am aiming to click the edit and delete button for a specific user. Please find the attached screenshot for reference.
Screenshot
I am trying to click the edit and delete button for the user 'Cierra' hence I have created the customize XPath '//div[contains(text(),'cierra#example.com')]//following::div[text()='Insurance']//following::div//div//span[#title='Edit']'
Trying to click the edit and delete button using the contains text with email 'cierra#example.com' however I see four results even I use the unique username. Could anyone help me with this?
(//div[contains(text(),'cierra#example.com')]//following::div[text()='Insurance']//following::div//div//span[#title='Edit'])[1]
you can enclose the result in bracket and call [1] , to get first one:
But you don't have to over complicate it , just get email then go back to parent and get span under that parent ,:
//div[contains(text(),'cierra#example.com')]/..//span[#title="Edit"]
if you still want to use fancy xpath locator then use :
//div[contains(text(),'cierra#example.com')]/following-sibling::div[contains(text(),'Insurance')]/following-sibling::div//span[#title='Edit']

VBA selenium to click on a nearby grid column

A problem derived from my previous question:" VBA to find if an element contains certain texts"
I find the desired text using :
driver.FindElementByXPath("//*[#class='x-grid3-cell-inner' and text()='TEXT']")
but it is unclickable. The box in the next column is where i want to click.
How to click a nearby grid column ?
Ca72-4 is what i try to find.
The grid row of Ca72-4 may differ.
Path of the text (in selenium) :
xpath=//div[42]/table/tbody/tr/td[3]/div
The yellow box on the right is input.
Path of the desired target (in selenium) :
xpath=//div[42]/table/tbody/tr/td[4]/div
Thank you for your help.
To click() in the adjascent cell next to the text Ca72-4 you can use the following xpath based Locator Strategy:
driver.FindElementByXPath("//div[#class='x-grid3-cell-inner' and text()='Ca72-4']//following::td[1]/div").Click
A solution may be to dim an integer and to loop and check all div[#] and then use the integer with targets xpath. But i'd really like to avoid loops if possible.

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

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)]

How to traverse all the element of dropdown in Selenium WebDriver?

I have a drop down on my web page and I have to traverse this drop down and select the specific one.But its not so simple, In this the traversing should be show by the hover and at last the specific element or item should be selected.(The mouse hover action should start from the first element till the required element and then select the element).
You need to look into Select, there are a couple of different ways of selecting elements from the dropdown, below is one example.
Select dropdown = new Select(<WebElement>);
dropdown.selectByVisibleText("text");

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'.