In my anchor tag, I don't have any id. But I need to get that value in Httpunit in-order to click.
Here is the anchor tag:
Continue
Please let me know it clearly.
you can actually get this like
//a[contains(.,'Continue')]
//a[starts-with(.,'Continue')]
//a[not(#id)]
//a[contains(#href,'#')]
what ever you like
i recommend you to see w3schools
and Google it before asking some very basic questions.
You'll find the anchor as part of the links supplied by WebResponse.getLinks ...
WebResponse page=wc.getResponse( ...
.. page.getLinks() ...
Related
I am trying to find out the xpath for first name of the facebook page and I have ended it with the following xpath: "**//div[1]/div[1]/div[1]/div[1]/input[#class='inputtext _58mg _5dba _2ph-']**" which is correct. My question is that, there are total 9 div tags on the page but I got it with the fourth div, I am not getting the reason how it's finding it in fourth div?
Page is Facebook home Page and element to find with xpath is Fist name input box
Please help me to understand how it's finding the element using above xpath
I know there are other ways to find xpath but I want to know the reason how it's finding it
I hope I am providing the complete information for the asked question if not let me know
Well it's because your xpath starts with a //. In literal english, it says find a DIV whose child is a DIV whose child is a DIV whose child is a DIV whose child is your INPUT. In your case, it does find a DIV which has INPUT as described by your xpath.
If you replace that // to single /, it will find the first DIV and then will try finding your input. Which it won't be able to find since .. like you said there are 9 DIVs.
Hope that paints a picture. Let me know if you need more explanation.
I am trying to enter text on search text box on google home page. That I can identify using xpath as //*[#id="q"]. But I wanted to reach to that element using parent child relationship. I am using xpath as below :
`(//form[#id='a'])/div[2]/input[#id='q']`
But when I am running the script, it is giving error that said "no such element". Can someone please tell what I am missing in writing the xpath?
Please upload your HTML code to let us know of the issue better. Meanwhile, Try this .//form[#id='tsf']//input[#name='q'].
Hope it helps.
I'm trying to use Watir to grab a specific link on a page:
Screenshot: Here is the href I am trying to grab.
My guess is I need to specify the ancestor element biz-website(?) then traverse down to the a tag and grab its href somehow, but I'm not sure what the syntax of my code would need to be do that.
Any ideas or tips?
You should be able to get the value of the href with
browser.span(:class, 'biz-website').a.href
If the class 'biz-website' is not unique for spans on your page, you can also use 'biz-website js-add-url-tagging'. If that is still not unique, you could also try
browser.span(:text, 'Business website').parent.a.href
abc
I am not able to locate above element. I tried //*[#id="contact-groups"], but with no success.
Well, XPath is not the best of the methods to find elements. But following will match the links with href = "#".
//a[#href="#"]
Not sure if your scenario is as simple as your question. I did test this with a simple html page.
The locator seems correct. You could try this too:
.//*[#id='contact-groups']
As per HTML code provided you can try below xpaths
//a[#id='contact-groups']
//a[contains(text(),'abc')]
//a[#href='#']
Thanks
I am guessing the link is in an Iframe.
Use the following code to switch to the frame and then click on the link
driver.switchTo().frame("frame-name");
driver.findElement(By.xpath("//a[#id='contact-groups']")).click();
I am trying to click on "Log in" link present on home page of "stackoverflow" using xpath as show as below. But no success
driver.findElement(By.xpath("//a[contains(text(),'log in')]")).click();
Please help what i m missing here.
Thanks
Use the following xpath:
//a[#class='login-link'][text()='log in']
I tried personally and it worked with me. Hope it helps.
The xpath which you have used in your question returns two webelements:
log in
log in
that's why selenium is not able to click on that.So use
//a[#class='login-link'][text()='log in']
Try this :
driver.findElement(By.xpath("//a[#class='login-link' and .='log in']").click();
Above XPath match <a> tag having class attribute equals "login-link" and inner text equals "log in".
General tip: always prefer . over text(). There are very rare situations when you have to filter element specifically by using text().