Unable to make xpath work for an HTML block of code

I have this html block: <td><a href="#" class=""> <i class="far fa-times mr-1"></i>Cancel</a></td> I wrote the following xpath to find this Cancel anchor, but this is not working. What am I doing wrong? //a[contains(text(), ‘Cancel’)] The following xpath works but i need to learn what am i doing wrong in the above one: //i[@class=’far fa-times mr-1′]/..… Read More Unable to make xpath work for an HTML block of code

Why can I find the first, but not the 2nd element with Xpath?

I am trying to build a test in Selenium Webdriver to check the values of 2 divs that have the same class name. Eg, HTML: <div class="prod-card"> <div class="prices"> <div class="price-wrap"> From: <div class="price">$9.99</div> </div> <div class="price-wrap"> To: <div class="price">$19.99</div> </div> </div> </div> I’ve been trying to use Selenium’s Xpath locator, but cannot seem to… Read More Why can I find the first, but not the 2nd element with Xpath?

Selenium find_element(By.XPATH, '') cannot locate the element

Here is the website: https://opensource-demo.orangehrmlive.com/ I tried to login. And I find the username for HTML: Here is my attempt, but it has the error that the element cannot be located. from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By service = Service(r’D:\Softwares\chromedriver.exe’) options = webdriver.ChromeOptions() driver = webdriver.Chrome(service=service, options=options) url =… Read More Selenium find_element(By.XPATH, '') cannot locate the element

Selenium (python) : finding an element relative to a previously-found one

I’m web-scrapping a page with the selenium module in python. I’ve looked for a certain element, and found it, like this: drv = webdriver.Firefox(options=opt) drv.get(url) x = drv.find_element(‘xpath’, ‘.//div[@class="col-lg-2 col-md-3 col-xs-6 guest-item "]’) Now I’d like to do a search for another element, using an XPath expression, but only inside the sub-tree that is below… Read More Selenium (python) : finding an element relative to a previously-found one

XPath expression to select all button or input type submit/button elements

I’m writing a Python script that uses Selenium to select all clickable buttons by XPath. I have these XPath expressions: //button //input[@type=’submit’] //input[@type=’button’] Is there a way to join these in a single XPath expression, to select only these types of elements? >Solution : You can check for the names and the attributes //*[name()=’button’ or… Read More XPath expression to select all button or input type submit/button elements

selecting indexed xpath in python

on the following url there are 3 score cards. https://www.basketball-reference.com/boxscores/?month=4&day=8&year=2023 I’ve tried many different variation of the xpaths to try and access the second one but the first one linking to the box score keeps being returned. score_card = WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.XPATH, "(//div[@class=’game_summary expanded nohover ‘])[2]/p/a"))).click() I’ve tried many different ways of changing it and can’t… Read More selecting indexed xpath in python