0

I have to send the string to the textfield in the webpage . I tried to access it by xpath but the xpath keeps on changing everytime I open the webpage newly. So I decided to access it using class name or tag name. But I am getting an error that the keys can not be passed to the access field.

HTML of the textfiled in the webpage:

<div class = "SearchBox">
   <input aria-label = 'xyz' placeholder = 'abc'>
</div>

I tried with these lines of code but none of it is working:

    text = driver.find_element_by_xpath('//div[contains(@class,'SearchBox')] and input[contains(@aria-label,'xyz')]')

    text =  driver.find_element_by_class_name('SearchBox')

    text = driver.find_element_by_xpath("//div[@class='SearchBox']/input")

    text = driver.find_element_by_xpath("//div[@class='SearchBox']/input[contains(@aria-label,'Combobox expanded. Use arrow keys to select available options or type to search.') and @dojoattachpoint='_searchInput']")

What am I doing wrong? Kindly help.

Error Log:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    l.send_keys("abcdef")
  File "C:\Users\Pavan-Kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
    'value': keys_to_typing(value)})
  File "C:\Users\Pavan-Kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Pavan-Kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Pavan-Kumar\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
  (Session info: chrome=65.0.3325.146)
  (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.17134 x86_64)

HTML Code Pic:

HTML Code

5
  • dont see any error..please post more code or atleast the url which you are trying to scrape Commented Sep 24, 2018 at 16:00
  • @Sarthak Negi Actually it is IBM jazz server.You got to have a account to access the webpage. Commented Sep 24, 2018 at 16:09
  • paste the error log as xpath of Access_text looks wrong by the quotes Commented Sep 24, 2018 at 16:16
  • @thebadguy I have edited the question.Please have a look now. Commented Sep 24, 2018 at 17:21
  • @gopalakrishna Update the question with text based HTML Commented Sep 24, 2018 at 18:26

2 Answers 2

2

The xpath that you jave written contains identifiers of both the div tag and the input tag. How will Selenium understand that you are trying to access the input field!!!! If you are trying to use the div tag as an anchor to reach the input tag, your xpath should look something like this... //div[@class='SearchBox']/input

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

2 Comments

I tried this .Its not working.I have edited the question please have a look now.
Is there another div tag with class 'SearchBox' somewhere higher up the DOM that has style -> display:none???
2

The below xpath should help you as per the html structure image you shared.

//div[@class='SearchBox']/input[contains(@aria-label,'expanded') and @dojoattachpoint='_searchInput']

4 Comments

This should nail the OP
@KireetiAnnamaraj Thanks for the answer, but it did not work.Error Log:raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
@Keerti Annamaraj I tried with this : text = driver.find_element_by_xpath("//div[@class='SearchBox']/input[contains(@aria-label,'Combobox expanded. Use arrow keys to select available options or type to search.') and @dojoattachpoint='_searchInput']")
@gopalakrishna, 'Element not visible' exception is thrown when the element though is present in the DOM but not displayed. However, did it work after changing the xpath to: //div[@class='SearchBox']/input[contains(@aria-label,'Combobox expanded. Use arrow keys to select available options or type to search.') and @dojoattachpoint='_searchInput'] as you mentioned? If not, try with this xpath //div[contains(@style,'')]/div[@class='SearchBox']/input[contains(@aria-label,'expanded') and @dojoattachpoint='_searchInput']. If still not visible, you need to debug why it is not displayed.

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.