Selenium's get_attribute method is not providing a value

Below is the code I am currently working with:

url="https://www.betexplorer.com/soccer/poland/ekstraklasa/lks-lodz-lechia-gdansk/fgQY4hAD/"
browser = webdriver.Chrome()

browser.get(url)
time.sleep(1.5)

trs = browser.find_elements_by_xpath(".//div[@id='odds-content']/div/div/table/tbody/*")

My goal now is to extract the "data-opening-odds" class within that xpath. This xpath corresponds to the green line on the image below, and I aim to scrape the red line. Image

I attempted to use

trs[0].get_attribute("data-opening-odd")
, but it's returning a None type.

Answer №1

If you are looking for the attribute "data-opening-odd" within the td element, make sure your xpath is targeting only td elements with that attribute, not tr elements. Use the following xpath to select only tds with the given attribute:

tds = driver.find_elements_by_xpath("//table[@id='sortable-1']/tbody/tr/td[@data-opening-odd]")

Alternatively, you can achieve the same result using a css selector:

tds = driver.find_elements_by_css_selctor("table#sortable-1 > tbody > tr > td[data-opening-odd]")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An Easy Solution to the "TypeError: fit_transform() requires 2 positional arguments but received 3" Error

Trying to create a complex pipeline using custom classes resulted in an error: TypeError: fit_transform() takes 2 positional arguments but 3 were given Despite attempting solutions found for similar issues, the error persisted. class NewLabelBinarizer(L ...

Fuzzy background when you scroll

My container has an image that blurs when you scroll down the page by 50 pixels. I feel like I've seen this effect somewhere before, but I can't quite recall where. I want the text to remain unaffected and not turn blue. Here is the HTML: <d ...

Font malfunctioning on Microsoft Edge and Internet Explorer

Apologies if this seems like a silly question, but I recently imported a font from my computer into a CSS file. While it displays correctly in Chrome, it's not working in Microsoft Edge or Internet Explorer. Unfortunately, I don't have access to ...

Creating a 3-column div with varying sizes of text in another div at the center position

I am attempting to create a 3-column layout using only DIVs, but I am facing some challenges. If I were to use tables in the traditional HTML 4 way, I could achieve this: <div style="width:100%"> <table width="50%" align="center"> ...

Maintaining hover effects even when elements are not in view

I am facing an issue with my absolutely positioned <div> (which serves as a menu) located in the corner of a webpage. The problem arises when I try to animate it on hover, but as soon as the cursor moves beyond the viewport, the hover action stops. I ...

A guide to replacing or customizing standard components in ReactJS

I need to modify the color property of a common component so I can use it elsewhere. const ViewAllIcon = (props) => ( <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 26 ...

How does Word2vec perform its operations on analogies?

Based on information found at https://code.google.com/archive/p/word2vec/: A recent discovery revealed that word vectors are able to capture various linguistic regularities. For instance, performing vector operations like vector('Paris') - ve ...

On mobile devices, the alignment of text in Bootstrap doesn't appear as intended

I'm creating a portfolio website for showcasing my design projects from university. The text in the "my work" section is centered, but it seems misaligned with other elements like buttons when the window width is reduced. What could be the issue? Cod ...

A step-by-step guide to graphing data points with Basemap

A numpy array named precip_subset holds data in the shape of (31, 60, 48). This array is a result of merging 31 datasets where each position represents unique values for precipitation. For example, accessing the value at index [1,0,32] returns 1.05. The c ...

tips for efficiently using keyboard to navigate through tabs in an unordered list

Utilizing unordered lists in this web application. I am looking to implement tab navigation with keyboard functionality. How can I achieve this? The first tab should contain text boxes, and when the user fills out a text box and presses the tab key, they s ...

The hyperlink for social media is not functioning properly within a list element

Having some trouble with the href-tags for social media on my contact page. Clicking on them doesn't seem to do anything. Any ideas on what might be causing this issue? html { height: 100%; box-sizing: border-box; background-color: #001725; ...

What is the best location to place the "get current URL" method while implementing page objects in Selenium?

When attempting to confirm whether the current URL matches the homepage URL, is it recommended to include the logic for retrieving the current URL directly within the test method, as shown in let currentUrl = browser.getCurrentUrl();, or should this logic ...

Instructions on deactivating the background when the sidebar is displayed and closing the sidebar by clicking anywhere other than the sidebar

I'm in the process of creating a sidebar for my website. When the sidebar is displayed (by clicking showRight), I want to disable the background content so that the user can't interact with anything outside of the menu. If the user clicks on th ...

Utilize CSS in the same way as the legend tag styling

I'm looking to create a stylish border around my HTML component. While I know the HTML legend element can achieve this, I want to use it outside of a form. For reference on using HTML Legend: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml ...

Trick for using :checked in CSS

Is it possible to change the color of a deep linking div using an input checkbox hack in the code below? <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /&g ...

Encountering org/openqa/selenium/remote/SessionNotFoundException error while executing JMeter tests in Jenkins

Recently, I encountered an issue when trying to run web app JMeter tests using the Firefox Driver in Jenkins. I was able to successfully execute the tests in non-GUI mode on the terminal of the Jenkins server. I could also run the tests successfully on th ...

How about trying out the magic of Bootstrap columns?

My issue pertains to bootstrap columns. Whenever I zoom in on the browser, the columns start overlapping and the text from col-md-7 ends up over the image. Does anyone know of a solution to this problem? <div class="row"> <div class="col-md-5 ...

Enhance your website design with Bootstrap's unique styling for jumbotron elements

I am currently working on developing a mobile website for calendar events and I need some help. Here is the basic version of the site that I have created so far: The issue I am facing is that the purple backgrounded areas only cover the text, rather than ...

Having Issues Getting Results from Curl Post Scraping

I am trying to scrape data from the website marcanet.impi.gob.mx/marcanet/controler/RegistroBusca using the code below, but I am unable to reach the result page. $form_url = "http://marcanet.impi.gob.mx/marcanet/controler/RegistroLista"; $data_to_post = a ...

A step-by-step guide on rotating a solitary image within HTML

Is there any way to make these three images in my table rotate continuously? I've looked everywhere for a solution but can't find anything. I want the rotation to mimic that of a planet rotating on its axis. Check out this one: BARCELONA <t ...