I'm trying to grab an element (some date in a calendar) based on its background color. As you can see in this short example Sunday doesn't have a background color, but Monday does:
<td class="rcWeekend" title="Sunday, December 17, 2017"><a href="#">17</a></td><td title="Monday, December 18, 2017" style="background-color:#3C9770;">
I'm using Chrome to get an Xpath and I'm getting this:
//*[@id="ctl00_cphBody_rdcAvailableDates_Top"]/tbody/tr[4]/td[4]
I'm trying to make my path a little more robust and instead of selecting specific row and column I would just like to be able to get the very first available button with a background-color
property. So I tried this:
browser.find_element_by_xpath(//*[contains(@style, 'background-color:#3C9770;')])
and this:
browser.find_element_by_xpath(//*[@id="ctl00_cphBody_rdcAvailableDates_Top"]/tbody/*[contains(@style, 'background-color:#3C9770;')])
And some other variations of that xpath... But I'm always getting an error. Can someone please advise how can I write this path correctly? Thank you!
在xpath值中使用引号
browser.find_element_by_xpath("//*[contains(@style, 'background-color:#3C9770;')]")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.