Issue
Im trying to get videos length using xPath but the aria-label changes on every video it looks like this //*[@aria-label="10 seconds"]
How can i specify this element path here's the html source
<span id="text" class="style-scope ytd-thumbnail-overlay-time-status-renderer" aria-label="20 seconds"> 0:20 </span>
Solution
If this id is unique text
directly try to extract the .text
or do a .get_attribute
Using .text
:
video_len = driver.find_element_by_id('text').text
print(video_len)
Using .get_attribute()
:
video_len = driver.find_element_by_id('text').get_attribute('aria-label')
print(video_len)
PS : Please check in the dev tools
(Google chrome) if we have unique entry in HTML DOM
or not.
Steps to check:
Press F12 in Chrome
-> go to element
section -> do a CTRL + F
-> then paste the xpath
and see, if your desired element
is getting highlighted with 1/1
matching node.
You can try the same two methods with the below css
span.style-scope.ytd-thumbnail-overlay-time-status-renderer
always check in HTMLDOM, if we have unique entry or not for any locator.
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.