How to locate an element using whole html(innerHtml) content - c#

How to locate an element using whole html content such as Download
Please help.

use the below as cssSelector:
a[href*='view_download_report(document.MForm']
it will give u this element.

you can also use xpath:
.//a[#href='javascript:view_download_report(document.MForm,
'mm_tt_uu_999','~','D')']

Related

Unable to locate WebElement using Selenium C#

I've been knocking my head trying to figure out why I can't locate and click this web element!
What I'm trying to do is pretty straightforward, I'm trying to click on any item of the following list: worten list of airpods
And I'm basically trying to locate AND click in some element of this kind:
It's completely impossible. Any help would be greatly appreciated.
I've already tried every type of xpath that I could remember, the only thing that comes close to working is when I copy the full xpath directly from the browser, but even then another error appears stating that the element isn't clickable...and obviously I don't want to deal with a full xpath.
examples of xpaths tried:
//a[#data-sku='7328250'] and its variations (#href instead of #data-sku, etc...)
same thing but with css selectors.
As per the snapshot provided to click on the desired element you can use the aria-label attribute of the <a> element and inducing WebDriverWait for the desired ElementToBeClickable() you can use either of the following Locator Strategies:
Using CssSelector:
IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("a[aria-label^='APPLE Airpods Pro 2ª Geração']")));
Using XPath:
IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[starts-with(#aria-label, 'APPLE Airpods Pro 2ª Geração')]")));

How to locate the element inside the <p> tags?

I have a few elements inside this kind of tag as below:
enter image description here
How do I locate these kinds of elements
I tried to locate the foresaid element, which the Selenium C# is not working
You can use xpath to locate the p element:
//div[#data-testid='patientLink']/p
Later you can call the getText() of the element located by the above selector.
give the p tag you are looking for an id. Then lookup the element using
var driver = //whatever your driver is;
driver.FindElement(By.Id("element-id-goes-here"));

Selemium can't find elements on a website

I'm using C#, and I can't get the the settlementdate in a textbox from nested tables. Can you please help me?
I've tried the following:-
driver.FindElement(By.Id("settlementdate"))
driver.FindElement(By.Name("settlementdate"));
driver.FindElement(By.Name("//*[#id='settlementdate']");
driver.FindElement(By.Name("//input[#id='settlementdate']");
See below for the html code on the website
try
driver.FindElement(By.Xpath("//table/tr/td/input[#id='settlementdate']");
To locate the desired element so you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:
CssSelector:
IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("table#headtable tr td input#settlementdate[name='settlementdate']")));
XPath:
IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//table[#id='headtable']//tr//td//input[#id='settlementdate' and #name='settlementdate']")));
Thank you for your help. I've managed to fix the issue.
The inputbox was in a frame, and I used driver.SwitchTo().Frame() to switch to the frame.

How to click an element without id inside div without class using Xpath and C#

I am supposed to click the link (highlighted blue, refer to image above), but LinkText does not work. I also tried using CSSSelector and XPath, but both:
_driver.FindElement(By.CSSSelector("HH3"]")).Click();
_driver.FindElement(By.XPath("div[text()="HH3"]")).Click();
doesn't work. Help?
Your tried locator looks incorrect, you should try using xpath with text to locate desire element as below :-
_driver.FindElement(By.XPath(".//div[text()='HH3']")).Click();
Try _driver.FindElement(By.XPath("//div[contains(text()='HH3')]")).Click();

Retrieve the dynamical link text using Selenium

Goal:
Select the second link, from top, by using By.LinkText
<a class="ng-binding" href="#/test/id_var1">324 fff</a>
<a class="ng-binding" href="#/test/id_var2">44 gggg</a>
Problem:
In this context the link text 44 gggg is not static because the link text changes every time the page is refreshed.
My idea is to retrieve all class="ng-binding" and then use the second link as a linkText, but I don't know how do it?
The answer is simply that it is impossible. You cannot get an element by link text if this text is dynamic and you don't know the value.
You could select it using other methods though.
css-selector
a[class='ng-binding']
tag-name (not recommended as it is probably not unique)
a
class-name
ng-binding
xpath
//a[#class='ng-binding']
Find the elements in a list and pull out the one you need.
Another option is selecting the 2nd element immediately using xpath.
(//a[#class='ng-binding'])[2]
use the below as cssSelector:
a.ng-binding[href$='/test/id_var2']// this will return the second link.
if u want to get all the elements using the
ng-binding
class, use the below as cssSelector
a.ng-binding//return all elemtns using the ng-binding class
You can also use below xpath:
//a[#href="#/test/id_var2"]

Categories

Resources