1

I have been trying to locate to the following element:

<input type="text" ng-change="vm.refreshTimeline()" button-enter="vm.filterRowChange();" ng-model="vm.filterRowValue" class="ng-pristine ng-untouched ng-valid ng-empty">

Its is a search box.

I tried using class name, xpath, css selector but none of these are working. Still i am getting "Unable to locate the element" with the respective attributes.

driver.find_element_by_css_selector('body > div:nth-child(1) > div.uiview.ng-scope > div.container.asset-details.ng-scope > div.row.top-buffer > div > div.GanttController > div.input-append.text-center.search_section.ng-scope > input')

driver.find_element_by_class_name('ng-pristine ng-untouched ng-valid ng-empty')

  find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/div[4]/div/div[2]/div[1]/input')

find_element_by_link_text('Search by Equipment ID or S/N')

I even tried using xpath helper to find out the exact xpath, but it is showing an error as:

[INVALID XPATH EXPRESSION]

Help me to overcome this issue.

Thanks in advance.

1
  • Try find_element_by_xpath("""/html/body/div[1]/div[2]/div[1]/div[4]/div/div[2]/div[1]/input""") Commented Dec 4, 2018 at 6:40

2 Answers 2

3

The desired element is an Angular element so to locate the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.ng-pristine.ng-untouched.ng-valid.ng-empty[ng-change*='refreshTimeline']")))
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='ng-pristine ng-untouched ng-valid ng-empty' and contains(@ng-change,'refreshTimeline')]")))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your time. I tried in all the ways which you said but still i am unable to locate the element.
@SaikumarK Your comment doesn't helps me either. Sorry, the answer didn't help you to solve your problem but how am I going to improve my post with that feedback?
0

Lets Set Implicit Wait Timeout:

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

It maybe take too much time to perform all and it needs to wait in order to guarantee the whole of elements.

For more information: Wait Timeout Selenium

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.