I want to find images, which doesn't have an ALT attribute (not having it empty, like alt="").
I've tried //img[not contains(#alt)], but it seems to be wrong. Is there a method to match such images?
Try the below xpath.
//img[not(#alt)]
Related
See my code here of my scenarioI have this scenario and I need to use xpath to validate the image, and the gradient colors are present. I tried all kind of xpath combination but still getting errors or not finding it. Many other samples have the style in-line. In this case has a "." class outside of a close tag. code in the image
Could some offer a hand?your text
I need to click a link in a grid that contains a particular img on the same row. I can easily find the correct img I want with:
//img[#src='./assets/images/not_evaluated.svg'].
However, when I issue the click with it, it doesn't work because the image is not clickable. However, the same row contains the link I want to click. The xpath to the clickable link is:
//a[#class='veracodelink']//span[contains(text(),'Static Scan')].
I need to combine these 2 xpaths to get the correct link to click. I have tried many different things and combinations, but nothing seems to work.
Assuming that the image and the link are inside the same tr element, you could combine them like this:
//tr[.//img[#src='./assets/images/not_evaluated.svg']]//a[#class='veracodelink']//span[contains(text(),'Static Scan')]
Explained: //tr[...] here selects the correct row containing the image, and the rest then selects the clickable element relative to that.
If they are inside something else than tr, adjust accordingly.
So I finally figured this out myself: The xpath I needed is:
//div//vc-link//a[#class='veracodelink']//span[contains(text(), 'Static Scan')][../../../../../..//img[#src='./assets/images/not_evaluated.svg']]
I have just started using Google sheet's "IMPORTXML" formular to extract webpage meta data for a SEO project.
I am stuck with the following questions:
How to use this formular and XPATH to extract a list of images (on a
page), which don't have an alt tag?
Similar as the question above, how to extract a list of images (on a page), which have an alt tag?
How to extract a list of images (on a page), which do or don't have a
title tag?
Thank you for your help in advance!
Note:
See an example of my question here:
I also referenced the formular on this post http://slesinsky.org/brian/code/xpath_checker.html, which is very old and seemd no longer working.
For the images that have an alt tag, use
=IMPORTXML(A2, "//img/#alt")
For those that don't, use
=IMPORTXML(A2, "//img[not(./#alt)]")
Note that in your example, there is only one img with no alt, so the cell will appear empty, but the selection is made.
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();