WebDriver find by xpath where //input[#value='empty'] - selenium

I need to find an input element with an 'empty' value by xpath.
Something like //input[#value='empty']. I don't mean the word 'empty', but the value is empty or blank.
What Xpath will return such element?
Thanks

Since the link I posted in the comment is a potential solution
So, I thought to post it as an answer:
How do I select an empty element in XPath?
Edit:
Based on advice from the comment to duplicate the essential parts of the linked answer (incase the link becomes obsolete), please find it below:
You could use XPath's not() function.
a[#href='#'][#class='button save-as'][#title='SaveAs...'][not(text())]

Next time post html snippet so that people will understand parent and target element
the below code will work, but if more input fields with null values are there then more than one result will be returned. [i am sure below xpath will return many results]
so please include parent node in below xpath
//input['not(text())']
the input belongs to text area, submit button, radio button , check box ....
again, post the HTML snippet next time. when you ask question related to xpath.

Related

Identifying an element from a group, span[i] is the differentiating factor

I have added the screenshot I have a group of elements that have the exact same xpath except the span tag.I want to identify the individual input fields, but unable to.
I have tried using contains, with class but unable to attach span to the xpath
Here is what the HTML looks like:
/html/body/div[#id='app']/div/div[#class='LayoutModify_LayoutModify_1Akxb']/main[#class='LayoutModify_main_5aBy3']/section[#class='sub-detail inner ProductDetail_productdetail_bJWN2']/div[#class='ProductDetail_productsphere_kgNGm']/div[#class='ProductDetail_threecol_2zA1n ProductDetail_productsphereleft_2pLZT']/span[4]/div[#class='el-input el-input--medium ProductDetail_productsphereinput_3eVZg']/input[#class='el-input__inner']
/html/body/div[#id='app']/div/div[#class='LayoutModify_LayoutModify_1Akxb']/main[#class='LayoutModify_main_5aBy3']/section[#class='sub-detail inner ProductDetail_productdetail_bJWN2']/div[#class='ProductDetail_productsphere_kgNGm']/div[#class='ProductDetail_threecol_2zA1n ProductDetail_productsphereright_3BrqC']/span[4]/div[#class='el-input el-input--medium ProductDetail_productsphereinput_3eVZg']/input[#class='el-input__inner']
Notice the span[4] and span[15] are the only differences
Quick question:
do either of these locators:
locator A
//span[4]/div/input[#class='el-input__inner']
locator B
//span[15]/div/input[#class='el-input__inner']
find any input on Your page?
If not - could You please post here the whole HTML page code here please?
Here is the xpath that worked:
//div[contains(#class,'ProductDetail_productsphereright')]/span[4]/div/input

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 locate links from Google results

Scenario:
open "google.co.in".
click in the search input box.
type something.
click Enter.
get the text of all links.
The xpaths of some links are:
.//*[#id='rso']/div[2]/div/div[2]/div/div/h3/a
.//*[#id='rso']/div[2]/div/div[3]/div/div/h3/a
.//*[#id='rso']/div[2]/div/div[4]/div/div/h3/a
.//*[#id='rso']/div[2]/div/div[5]/div/div/h3/a
.//*[#id='rso']/div[2]/div/div[6]/div/div/h3/a
All the xpaths have the same pattern. the third div needs to be incremented by 1 to get the next xpath. I've read somewhere that in the scenarios like this generic xpath can be used. According to his suggestion, the xpath will be ".//*[#id='rso']/div[2]/div/div/div/div/h3/a". just removed the predicate of the third div. This is not working. Is this the way to locate elements?
You can try below XPath to fetch all result links:
//div[#class="g"]//h3/a
If you want to avoid links from "People also ask" block:
//div[#class="g"]//h3/a[not(ancestor::div[#class="_OKe"])]

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']")));

selenium getXpathCount

HI there
selenium.getXpathCount does not find element, any one hoas any idea ? Here is my code:
if (existArtist){
int result = selenium.getXpathCount("//*[#id='chugger-results']/div[1]/ul/li").intValue();
if (result>0){
//DO THIS
Either you have a broken DOM (Do a W3C Validation and see if you have any unclosed tags) or your XPath is looking for an element that doesn't exist.
We would need to see the entire HTML of the page to be able to answer your question (more visibility of your test code would be useful too)