Tried using
By.id("aaabICLL.AreaViewStatic.ServiceLink17"), By.className("urLnkFunction"),Xpath, linkText("Serviceman Basic Report")
And for these encountered this error:
NoSuchElementException.eclipse is unable to locate the "Serviceman Basic Report" hyperlink.
Serviceman Basic Report
You can use following xpath for your case:
driver.findElement(By.xpath("//*[contains(text(),'Serviceman Basic Report')]")).click();
Hope it will help you.
Related
I'm trying to enter username and password to login to my bank account by VBA. I can find the password Input Tag to enter the password, but cannot find the userform Input Tag at all. I tried the following methods one by one, but none of the Find methods worked and there is no other attributes for this tag which I can look for
Dim Mybrowser As New WebDriver
Set Mybrowser = New WebDriver
Mybrowser.Start "chrome"
Mybrowser.Get "https://tbconline.ge/tbcrd/login?t=false"
Mybrowser.FindElementByName("loginUsername1633281403139").SendKeys ("test")
'or
'Mybrowser.FindElementByClass("fblock100 > .ng-valid").SendKeys ("test")
'or
'Mybrowser.FindElementByCss("css=.fblock100 > .ng-valid").SendKeys ("test")
'or
'Mybrowser.FindElementByXpath("//input[#name='loginUsername1633281403139']").SendKeys ("test")
'or
'Mybrowser.FindElementByName("loginPassword1633282058600")
Am I making a mistake in the code ? or is it true that sometimes we cannot find some elements by find method on a page, although they exist there ? Thanks for your advice.
The Name or CSS that you've used, looks brittle in nature, Probably generated by backend framework, so on every run they will change, Please use customize and optimize CSS or Xpath from below.
Note that CSS has more preference than XPATH
Please use this css for username
input[formcontrolname='username']
xpath
//input[#formcontrolname='username']
for password field :
css
input[formcontrolname='password']
xpath
//input[#formcontrolname='password']
You can learn CSS from here.
The name attribute value loginUsername1633281403139 seems to be dynamic so always use some static attributes to find elements or write reliable xpaths. Please see below different ways to find elements.
UserName:
CSS : input[name*='loginUsername']
xPath#1 : //input[#formcontrolname='username']
xPath#2 : //input[starts-with(#name,'loginUsername')]
xPath#3 : //input[#ng-reflect-name='username']
Password:
CSS : input[name*='loginPassword']
xPath#1 : //input[#formcontrolname='password']
xPath#2 : //input[starts-with(#name,'loginPassword')]
xPath#3 : //input[#ng-reflect-name='password']
I would suggest you to practice with finding locators. Please go through this tutorial it will helps you.
I have been looking for an XPath code to get the value of the attribute of an HTML element as part of my regression testing. Can anyone please help
the attribute value is dynamic changes for every next webelement
below is the HTML code
<figcaption id="recentVideosvideoname0" data-videono="xZA6FJ32Twe2GQYEuBHJnQ==" title="test for test" class="caption">test for test</figcaption>
i want attribute : data-videono
I have tried something like this
By.xpath(("//div[contains(#id,'recentVideos')]/div/a/figure/figcaption"));
Here is the Answer to your Question:
To retrieve the attribute data-videono you can consider to use the following line of code:
String my_attribute = driver.find_element_by_xpath("//figcaption[starts-with(#id, 'recentVideos') and #title='test for test']").getAttribute("data-videono");
Let me know if this Answers your Question.
Please follow the approach mentioned below:
driver.findElement(By.xpath("//div[contains(#id,'recentVideos')]/div/a/figure/figcaption")).getAttribute("data-videono");
You can get attribute value by using XPath itself.
XPath 1.0
"//div[contains(#id,'recentVideos')]/div/a/figure/figcaption/#data-videono"
Notice the #data-videono at the end of string, which will return attribute value (p.s. it seems like it is base64 encoded data)
I don't know if i got your question, but do you already tried:
String var = driver.frindElemnt(By.xpath("put your xpath in here")).getAttribute("data-videono");
This is what I have
1000000 Venelin-PPxo-P24-FAID-EUR
want to write an XPath for the a based on its contained text. I tried the below but it does not work
xpath=(//a[contains(text(),'-PPxo-P24-FA')])[2]
However, if I try with the below, it works
xpath=(//a[contains(text(),'-PPxo-P24-FAI')])[2]
I am using Selenium IDE 2.9.1 if that makes any contribution to my question.
Hi it seems your Xpath is incorrect
can you try following:
xpath = ("//a[contains(text(),'-PPxo-P24-FA')][2]")
Thank you for all of the answers, guys!
However, I found the solution. It looks like the website contains the text some more times than I need it to. The working code is:
xpath=(//a[contains(text(),'-P24-')])[6]
I have a celltable , where i have multiple rows and is a dynamic table,
Screenshot attached ..
What i want is to find the row where column contains useren#lim.mobi
and then click its checkBox.
I am trying with xpath but not much experience here , If i can get some help please
Thanks
Here is the html code of the specific cell
I don't know the exact html of your table to form an xpath would be difficult.
however it should look something like this
//*[contains(text(),'useren#lim.mobi ')]/../td[2]
for following table, if I have to find the corrosponding contact for some company, This is how I would do it.
https://www.w3schools.com/html/html_tables.asp
//*[contains(text(),'Magazzini Alimentari Riuniti')]/../td[2]
Please try with the following xpath:
//tr[./td[contains(text(),'useren#lim.mobi')]/td[2]/input
if above xpath is not working please attach html code screenshot so i can tell you the extact xpath.
This might help to solve your issue:
//td[#title="useren#lim.mobi"]/following::input[#type="checkbox"]
If you get NoSuchElementException with this XPath you might need to add ExplicitWait as below:
WebElementWait wait = new WebElementWait(getWebDriver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//td[#title='useren#lim.mobi']/following::input[#type='checkbox']")));
I am unable to enter a value in field which is having type as "text" after running the automated script. Please find details below
Field Name: "Spot/Content Name
Xpath value for the above field :
.//*[#id='154']/div[3]/div[1]/div/div/div/div[1]/div/div/div[2]/div/div[2]/input
Automated Script for the above Xpath:
driver.findElement(By.xpath(".//*[#id='154']/div[3]/div[1]/div/div/div/div[1]/div/div/div[2]/div/div[2]/input")).clear();
driver.findElement(By.xpath(".//*[#id='154']/div[3]/div[1]/div/div/div/div[1]/div/div/div[2]/div/div[2]/input")).sendKeys("Rose");
Error Message :
NoSuchElementException: Unable to locate element:
{"method":"xpath","selector":".//*[#id='154']/div[3]/div[1]/div/div/div/div[1]/div/div/div[2]/div/div[2]/input"}
I tried even the html which was shown on the xpath but it was not working.
This is not the way Xpath should be used, please go through the following link: so that you could understand it in a better way.
http://www.toolsqa.com/selenium-webdriver/choosing-effective-xpath/
Also it is always good practice to share you HTML code so that ppl could identify the problem.
Meanwhile your element can be found using CSSSelector also try this--
driver.findelement(by.cssSelector("input[id='154']")).clear();
driver.findelement(by.cssSelector("input[id='154']")).sendKeys("Rose");
Please let me know if this works..!!