Reputation: 47
I am trying to write a script using Selenium/Chrome webdriver that will find a video uploaded to click based on the title. The title is based on time of the day/date. Here is what I have so far (after logging in to the page and video title setting automatically),
web = webdriver.Chrome()
web.get(...website...)
videoTitle = "June 03, 2021 2nd Service"
time.sleep(5) #allow page to load all elements
lastUpload = web.find_element_by_xpath(".//*[text() = 'videoTitle']").text
print(lastUpload)
lastUpload.click()
When the script is finished, I get all text in the page, not just the video title. How do I change that? How do I get just the button for me to click on? The last line fails.
Here is what I see on the page for that specific button,
When I run the code, lastUpload prints all the text in the page, which is not clickable. From what I've seen searching other posts on here it appears that I need to remove "contains" from my search for the text. I did that, however I am getting the same results. Do I need to be more specific?
Last, all the ember### divs that come up generate new numbers every time the page refreshes, so I cannot use that to simply click the last item.
Thanks in advance! Much appreciated.
Upvotes: 0
Views: 437
Reputation: 1441
See if this works:
driver.find_element_by_xpath("//div[text()='June 03, 2021 2nd Service']//ancestor::a[@class='ember-view']").click()
Upvotes: 1