1

I'm using selenium to fill a webform, but this particular textbox for some reason is giving me trouble. The html for it is:

<input type="text" class="black_ar" value="" size="25" id="type" name="type" 
onmouseover="showTip(this.id)" onmouseout="hideTip(this.id)" 
onblur="trimByAutoTag(this);onSubTypeChangeUnit('className',this,'unitSpan')" 
autocomplete="off" title="">

I have used:

driver.find_element_by_name('type').click() 

and

driver.find_element_by_xpath('xpath').click() 

But they both say that the element cannot be found. I am not sure if it is in an iframe or not (if anyone knows a way to check) and am using chropath which is a chrome extension to find the xpath of the element.

Edit: chropath says under the relative xpath "It might be child of svg/pseudo/comment/iframe. XPath doesn't support for them." if that helps

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

4 Answers4

1

As per the HTML you have shared to click within the textbox you can use either of the following solutions:

  • xpath:

    driver.find_element_by_xpath("//input[@class='black_ar' and @id='type']").click()
    
  • css_selector:

    driver.find_element_by_css_selector("input.black_ar#type").click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

Now ChroPath supports iframe. So if you inspect any element and that element is inside iframe, ChroPath will tell that element is inside iframe as well as it will generate the relative xpath.

0

Open your page in browser let say chrome. Press right click on textbox and select inspect menu. In oped dev tools look if your textbox has parent iframe element. One way to do it:

  1. Click inside chrome dev tools and press ctrl+f
  2. In opened search field copy iframe input.black_ar

If does you have first switch to this frame function for switching frames in python, selenium

To locate your input use driver.find_element_by_css_selector(‘input.black_ar’)

Sers
  • 12,047
  • 2
  • 12
  • 31
0

Have you tried, driver.find_element_by_xpath("//input[@id='type']").click(); ?

You could all check by press F12 while in your browser, or going to developer tool; press Ctrl+f afterwards and type in //iframe and try to see if it exists in the page.