ScalaTest+Selenium equivalent of .getText() - selenium

I'm new to Selenium and ScalaTest, but I'm having issues finding Selenium+ScalaTest's counterpart to .getText()
For example, when I use selenium-java, I can retrieve text "Cat" by:
driver.findElement(By.id("firstHeading")).getText()
from:
<h1 id="firstHeading" class="firstHeading" lang="en">Cat</h1>
However, I can't figure out how to do this with ScalaTest, and my googling skills have failed me. Any help would be greatly appreciated, thank you!

I've figured out one working solution:
id("firstHeading").element.text should be ("Cat")
This lets me extract the text from an element by the id "firstHeading". Please let me know if there is a better/more acceptable approach. Thanks!

Related

Selenium C# - I'm unable to find an element on this page using any of the locators

This was just a random script I made to complete a quiz but I can't seem to access the final element. I want to select the element, click the element and then send some text to the element.
I have tried to access the input box by class name, CssSelector and by XPath.
The website is https://www.16personalities.com/free-personality-test
Here are the XPaths I have tried:
//*[contains(#class, 'email-wrapper')]
//div[contains(#placeholder, 'your#email.com')]
//div[#class="row request-info-wrapper"]
//*[#id='request - email']"
Any help is greatly appreciated as I'm new to the framework and would very much like to know what I'm not understanding about locators! Thank you!
EDIT:
I can't seem to target this element or any of its children:
You have selected wrong tag DIV.Try this following Xpath. All should work.
"//input[#id='request-email']"
Or
"//input[#name='email']"
Or
"//input[#placeholder='your#email.com']"
Your field has a (presently) unique ID of "request-email".
Thus you can simply use, as a CSS selector,
('#request-email')
Then, in you can simply tell Selenium to hit ENTER to save your data. Let me know if you need help doing that.

How to combine two xpath into single xpath

Please find screenshot
Xpath Expressions are :
1.xpath
//td[.//span='Large' and .//span='Angelfish']
2.Xpath
//td[.//span='EST-1']
Above two xpaths, i want to merge it into single xpath. I tried the below
//td[.//span='EST-1' and .//span='Large' and .//span='Angelfish']
but no luck. Any help is appreciated...
I think you are talking about the JPetStore site Angelfish table, you can try the below Xpaths :
//td[span[text()='Large'] and span[text()='Angelfish']]/preceding::td/a[text()='EST-1']
or
//td[span[text()='Small'] and span[text()='Angelfish']]/preceding::td/a[text()='EST-2']
But I'm not sure what value you need from that because your question is not clear and the given information also not enough.

xpath=(//a[contains(text(),'-PPxo-P24-FA')])[2] fails to select

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]

Find specific cell of a celltable with Selenium xpath

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='chec‌​k‌​b‌​ox']")));

Xpath for href element

I need to click on the below href element,which is present among similar href elements.
<a id="oldcontent" href="listDetails.do?camp=1865"><u>Re-Call</u></a>
Can anyone provide me xpath to click the above href link?
Try below locator.
selenium.click("css=a[href*='listDetails.do'][id='oldcontent']");
or
selenium.click("xpath=//a[contains(#href,'listDetails.do') and #id='oldcontent']");
This works properly try this code-
selenium.click("xpath=//a[contains(#href,'listDetails.do') and #id='oldcontent']");
This will get you the generic link:
selenium.FindElement(By.XPath("xpath=//a[contains(#href,'listDetails.do')")).Click();
If you want to have it specify a parameter then you will have to test for each one:
...
int i = 1;
selenium.FindElement(By.XPath("xpath=//a[contains(#href,'listDetails.do?camp=" + i.ToString() + "')")).Click();
...
The above could utilize a for loop which navigates to and from each camp numbers' page, which could verify a static list of camps.
Please excuse if the code is not perfect, I have not tested myself.
have you tried:
//a[#id='oldcontent']/u[text()='Re-Call']
for me worked //a[text()='Re-Call']
what worked for me:
//a[contains(#href,'logout')]
Below works fine.
//a[#id='oldcontent']
If you've tried certain ones and they haven't worked, then let us know, otherwise something simple like this should work.
Best way to locate anchor elements is to use link=Re-Call:
selenium.click("link=Re-Call");
It will work..