-2

I want to use selenium for clicking a textbox, but I get the error. It is a datepicker, when I click this textbox, the popup calendar should appear.

I used this code.

driver.find_element_by_xpath("""//*[@id="startDt"]""").click()

html code

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
sophia
  • 1
  • Screenshots of the UI are great, screenshots of code are not. Instead edit your question and add the HTML as text, properly formatted. Also, we don't know what error you got because it's not in your answer. Edit your answer and post the full error message, properly formatted. – JeffC May 24 '21 at 14:56

2 Answers2

1

Instead of this :

driver.find_element_by_xpath("""//*[@id="startDt"]""").click()

use this :

driver.find_element_by_id("startDt").click()

As well as check for Iframe, if the element is inside the frame the switch to frame first and then you can interact with the input tag

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • I've tried id, name, css_selector, and most of ways they recommend on Google, but i get the same errors.Thanks though. – sophia May 24 '21 at 07:30
  • As suggested please check for iframes, I think that could be an issue. – cruisepandey May 24 '21 at 07:30
  • @sophia : You are welcome ! Can you accept this answer if it was helpful to you ? – cruisepandey May 24 '21 at 07:59
  • If the problem was an IFRAME issue... this answer doesn't solve the problem and it should not be accepted. – JeffC May 24 '21 at 14:58
  • @JeffC : read this again `As well as check for Iframe, if the element is inside the frame the switch to frame first and then you can interact with the input tag` it was the idea given to the OP to switch to frame. I did not edit the answer as you can see. Enough info was not shared by OP at first place :) – cruisepandey May 24 '21 at 15:00
  • We shouldn't be giving answers to questions that have been answered 100x on SO already. If this is really an IFRAME issue, and it seems to be, it should be dup'd to https://stackoverflow.com/a/48729644/2386774. – JeffC May 24 '21 at 15:27
  • I agree that it was OP's lack of info that caused the problem but it should be addressed as I described above. – JeffC May 24 '21 at 15:28
0

1)Go to your browser -> Open the application manually

2)Open inspector window(i.e press function key f12 from your keyboard)

3)Go to console tab, type as below and click on enter:

$x("//*[@id='startDt']");

4)If the element is identified and count is 1 in console then your locator is correct but in Selenium you get NoSuchElementException, then there are high chances the element you are trying to locate is inside the Iframe. If so, figure out the Iframe and switch to it, then try to call findElement method, it should work.

5)If the element is not identified in the console, then your element with the xpath you are using doesn't exists/your xpath is wrong.

You can refer [link][1] for more info on evaluating and validating your xpath procedure

[1]: https://yizeng.me/2014/03/23/evaluate-and-validate-xpath-css-selectors-in-chrome-developer-tools/#:~:text=From%20Console%20panel,%22)%20to%20evaluate%20and%20validate.

Nischitha K N
  • 397
  • 1
  • 8