0
votes

I am new to this GUI Scripting.... My requirement is I want to click on the drop down arrow, & inside there are some elemets with tree structure to select the particular node/alarm..

So Intially I need to crack the XPATH for the drop down arrow of "COUNTERS" enter image description here

enter image description here Tired Xpath by using absolute Xpath as below :

        WebDriverWait(self.driver, 70).until(
            EC.element_to_be_clickable((By.XPATH,
                                        "/html/body/div/pm-application/epic-layout/div/div/div/div[5]/div[4]/epic-layout-panel/div/div/div/pm-reporting/epic-layout/div/div/div/div[3]/div[4]/epic-layout-panel/div/pm-tree-wrapper/div/div/div[1]/div[2]/div[1]/div[2]/div/div[2]/div/div[1]/div/div/div[3]/span/i")))

Also with Relative paths as well :

  1.        WebDriverWait(self.driver, 70).until(
             EC.element_to_be_clickable((By.XPATH, "//div[@id='1483f603-ed09-6586-16e8-fc074ea8f908']//span//i[@class='icon tree-node-arrow collapsed']")))
    
  2.        WebDriverWait(self.driver, 70).until(
             EC.element_to_be_clickable((By.XPATH,
                                         "//*[@class='virtual-tree']//*[@class='icon tree-node-arrow collapsed']")))
    
  3. WebDriverWait(self.driver, 70).until( EC.element_to_be_clickable((By.XPATH, "//i[@class='icon tree-node-arrow expanded']")))

But still I am facing below issue , Please help me to resolve this issues

AttributeError: 'str' object has no attribute 'find_element'

1
Provided code lines cannot be a reason for provided exception trace. Show exact line that causes the exception - JaSON
I have added the full html code in Screenshot, please have a look - yashu natesh
No need to check HTML code. Show your code. Exception is quite clear: you're trying to call method find_element from string object. Show code line with find_element. Also show what is EC in your code - JaSON
Below is the code I'm using - yashu natesh
def search_counter_in_performance_manager(self): try: WebDriverWait(self.driver, 70).until( EC.element_to_be_clickable((By.XPATH, "//div[@id='1483f603-ed09-6586-16e8-fc074ea8f908']//span//i[@class='icon tree-node-arrow collapsed']"))) WebDriverWait(self.driver, 70).until( except BaseException: logger.fatal("Fatal exception occurred inside Search Counter In PM()".format(self.name)) logger.error(traceback.print_exc()) In this Xcode Path includes numbers not the string - yashu natesh

1 Answers

1
votes

Please read about CSS selectors and Xpath selectors. Both of them don't like white or empty spaces.

It is a good practice to give Selenium the element actual tag, and not just asterisk sign.

Here is an example of the find element using CSS selector:

  • "div[class*='tree-node']"

This selector will return all the div elements that their class attribute contains the phrase "tree-node".

Using xpath you can find element by their attributes as well, or by the text written inside them:

  • "//div[contains(text(),'333')]"

This selector will give all div elements that have the text 333 inside them