0

I have an element developed using angular JS. Below are the information available when i inspect the element. I used the

driver.find_element_by_class_name("workstation-opconsultant-icon workstation-icon") 

to identify the element. But selenium not able to identify the element. please suggest how to identify the element.

<div _ngcontent-tby-c4="" class="homepage-tile"><div _ngcontent-tby-c4="" class="workstation-opconsultant-icon workstation-icon"></div><span _ngcontent-tby-c4="" class="font-bold homepage-tile-text text-white">OP Clinic</span></div>
sshashank124
  • 31,495
  • 9
  • 67
  • 76

1 Answers1

0

workstation-opconsultant-icon and workstation-icon are actually two classes. You can do

driver.find_element_by_class_name("workstation-opconsultant-icon")
# or
driver.find_element_by_class_name("workstation-icon")

If you want to locate by both classes use css_selector or xpath

driver.find_element_by_css_selector(".workstation-opconsultant-icon.workstation-icon")
driver.find_element_by_xpath("//div[@class='workstation-opconsultant-icon workstation-icon']") 
Guy
  • 46,488
  • 10
  • 44
  • 88
  • Thanks. I have tried the below and it is working. driver.find_element_by_css_selector(".workstation-opconsultant-icon.workstation-icon"). Is there any way to dynamically get the object property in case of change in value in near future – Pattabi Jan 09 '20 at 12:58
  • I mean if the value used in css selected is changed, what to do? – Pattabi Jan 09 '20 at 13:00
  • @Pattabi Do you mean something like class `workstation-opconsultant-icon` changes to `new-class-name`? – Guy Jan 09 '20 at 13:02
  • @Pattabi You will have to update the locator. I suggest you learn about [POM](https://stackoverflow.com/questions/18094238/what-is-the-page-object-pattern-in-selenium-webdriver) if you aren't using it already, it will reduce your maintenance to minimum. – Guy Jan 13 '20 at 14:06