0

I just want to say that I am new to Python/Selenium and I've been googling and wracking my head for hours now.

I am trying to extract a value from an element from the website we use for creating tickets at work. The thing is, the element with the ticket number has no ID and I cannot seem to be able to single it out using its other attributes.

The HTML for the elements is as follows:

<span class = "custom-field__value ng-binding ng-scope"
ng -
    if = "!$parent.editMode &amp;&amp; data.value" tooltip = ""
ng - bind - html = "((status.isCollapsed) ? (data.value | securelinky : '_blank')) || ('customField.label.noValue' | i18n)"> INC22963815 
</span>

So, I want to get the INC22963815 from the element.

I tried with

ticket = driver.find_element_by_class("custom-field__value ng-binding ng-scope")
ticket = driver.find_elements_by_class("custom-field__value ng-binding ng-scope")

for number in ticket:
    print(number.get_attribute("innerText"))

but I get nothing.

But when I tried with

ticket = driver.find_elements_by_tag_name("SPAN")

for number in ticket:
    print(number.get_attribute("innerText"))

I found the text I am looking for, but it also outputs almost everything else on the page, so it is not very useful.

So now I am resorting to asking the question myself. I need help just to single out that one element. Thank you in advance.

2 Answers 2

1

Have you considered using the element's XPATH? You can use the Chropath plugin https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo, to get the element's XPath.

You can then do something like

driver.find_element_by_xpath("xpath_string_here")

Let me know if this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

Yes! That worked! Thank you so much. I did try using XPATH, but I just copied it from the built-in chrome code inspector. But Chropath did it for me
1

I see you are using class name (that has spaces in it). Class name does not support spaces. so that's why it did not work. Moreover it's just a combination of multiple class separated by a space.

consider changing it to css selector :-

ticket = driver.find_element_by_css_selector("span.custom-field__value.ng-binding.ng-scope")

P.S :- it's not recommended to use automatic xpath or css generated by browser built in tools.

1 Comment

I did not know that about spaces. I will keep it in mind. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.