Xpath or CSS : Trying to create either one - xpath

I am trying to capture "Featured Courses" using either an xpath or CSS selector on the following link qaclickacademy website. Below is what I have tried.
By.xpath("//div[contains(concat(" ",normalize-space(#class), 'text-center'), " Test ")]");
Would you like to help me, please?

If you use the xpath //ul[#class="gallery course-list"] you'll get all the licontaining courses.
If you want the link in each a element you should try this:
//ul[#class="gallery course-list"]//a/#href

Related

How to click element on pseudo element ::after in Robot Framework

I would like to Click button at ::after but I don't know how to create xpath from pseudo element
I try this way //em[#class='x-btn-split']::after but it's not work.
Please anyone help.
You can use directly id='ext-gen33'. But if you want xpath only then include 2 attribute if there are many matching buttons
xpath = //button[#type='button' and #id='ext-gen33'].

Not able to identify element on Google Home page

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.

How to locate an element having href='#' attribute in anchor tag

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();

Xpath for Log-in

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().

xpath for a google search url issue no content

http://www.google.com/search?q=youtube
Trying to get the url part www.youtube.com/ of the search
using this xpath but there is no output from it.
.//*[#id='rso']/li[1]/div/div[2]/div[1]/cite
i've also tried using the css path same issue
CSS: div[aria-label='Result details']+div>div cite.
Btw, your xpath works fine for me. If you use selenium to retrieve your text for example, you should write xpath=.// in this case, because it recognize selector as xpath by preceding // symbols. Also //*[#id='rso']/li[1]/div/div[2]/div[1]/cite//text() will return three textNodes www., youtube and .com/

Resources