0

I am having issues getting an element from the netlify dashboard. The code I have currently selected the element and shows the base element the web developers set, so obviously, they update it with javascript however how do I get this. On my dashboard it states 1 MB but my output is 0 KB each time so it seems I am only getting the base text My code:

driver = webdriver.Chrome()
driver.get("https://app.netlify.com/teams/jimbob0119/overview")
element = driver.find_element_by_name("github")
element.click()
driver.implicitly_wait(10) # seconds
login = driver.find_element_by_name("login")
login.send_keys(email)
password = driver.find_element_by_name("password")
password.send_keys(passwordstr)
loginbtn = driver.find_element_by_name("commit")
loginbtn.click()
driver.implicitly_wait(10) # seconds
getbandwidth = driver.find_element_by_xpath("//dd[@class='tw-text-xl tw-mt-4px tw-leading-none']")
print(getbandwidth.text)

The HTML:

<dd class="tw-text-xl tw-mt-4px tw-leading-none"> 1 MB 
    <span class="tw-text-gray-darker dark:tw-text-gray-light tw-text-base">
        <span class="tw-sr-only">
            out of
        </span> /100 GB 
    </span>
    <span class="tw-absolute tw-mt-2px tw-w-full">
    </span>
</dd>

my output:

0 KB
out of
/100 GB
  • Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. Code includes HTML. – JeffC Apr 17 '21 at 14:34
  • `$3` is specific to the Chrome devtools and is not in the HTML so it cannot be fetched. If you tell us which value you're trying to get, we can help with that. – JeffC Apr 17 '21 at 14:36
  • okay will do sorry – James Westhead Apr 17 '21 at 14:37
  • Also, `implicitly_wait()` doesn't actually wait. What it does do is set a timeout for that instance of the driver. So, you only need to call it once, unless you plan to change the wait value from say 10s to 30s or whatever. The rest of the calls can be removed. – JeffC Apr 17 '21 at 14:38
  • I am trying to get the bandwidth my websites are using on netlify.com, it's updated to 1 MB however I only get 0 KB which is obviously it's base, or original state – James Westhead Apr 17 '21 at 14:55
  • Update your code to the code you are actually using now. `$3` doesn't work but it's still in your code. – JeffC Apr 17 '21 at 14:56
  • oh poop yeah forgot to change that that was from testing – James Westhead Apr 17 '21 at 14:58
  • Your HTML doesn't line up with your result but it looks like you are getting what you asked for. What is it that you need? You should edit your question further, especially the first paragraph where you are still referring to `$3`, etc. and state clearly what you are looking for. – JeffC Apr 17 '21 at 15:03
  • I made it clear in an earlier comment, on MY dashboard, it states 1 MB, I get 0 KB not what I want – James Westhead Apr 17 '21 at 15:06
  • Have you checked to see that your locator is unique? Open the dev console and use `$x()` to try your XPath locator and see if it returns 1 or more elements. If it's unique, put a 5s sleep before the `getbandwidth` line, does it work now? – JeffC Apr 17 '21 at 15:12
  • ```$x("//dd[@class='tw-text-xl tw-mt-4px tw-leading-none']") (4) [dd.tw-text-xl.tw-mt-4px.tw-leading-none, dd.tw-text-xl.tw-mt-4px.tw-leading-none, dd.tw-text-xl.tw-mt-4px.tw-leading-none, dd.tw-text-xl.tw-mt-4px.tw-leading-none] ``` – James Westhead Apr 17 '21 at 15:15
  • the time.sleep worked thank you – James Westhead Apr 17 '21 at 15:18
  • That wasn't intended to be the answer, just a debugging tool. Sleeps are not good practice. Now that we know a sleep works, we need to wait for that element text to change. See this answer... https://stackoverflow.com/a/30964981/2386774. – JeffC Apr 17 '21 at 16:01
  • Does this answer your question? [Selenium: Wait until text in WebElement changes](https://stackoverflow.com/questions/30964922/selenium-wait-until-text-in-webelement-changes) – JeffC Apr 17 '21 at 16:01

1 Answers1

0

JeffC figutrd it out by stating to put a time.sleep(5) before printing it thank you!