phantompain
phantompain

Reputation: 15

How can I extract ticket number from header element

another text headerI want use header and split digit numbers in header title but i cant print header I have to take numbers of searching it by link ; [html class]

(https://i.sstatic.net/xo2Ja.png)

Please help..

try:
    header = driver.find_element(By.PARTIAL_LINK_TEXT,'details__header-title')   
    print(header) 
    for c in (header):
    #    if c.isdigit():
            print(c)
except:
    header2 = driver.find_element(By.TAG_NAME,'ticket-message__body-message--text')
    print(header2)
    for a in (header2):
#if a.isdigit():
            print(a)

Upvotes: 1

Views: 71

Answers (1)

Prophet
Prophet

Reputation: 33353

UPD
Since all the desired header elements having details__header-title class and you want to get the ticket number appearing in the text in that element you can locate this element, extract it text and then extract number from the string, as following:

text_content = driver.find_element(By.CLASS_NAME,'details__header-title').text
ticket_number = int(''.join(sign for sign in text_content if sign.isdigit()))

Upvotes: 0

Related Questions