Python with Selenium: Cannot find element error
I am trying to populate a textbox but I cannot find the element.
I tried to find element
- by class
- by the name
- Added 10 seconds wait
But I am still getting the same error.
Here is the HTML
<div class="innerWrap">
<textarea aria-autocomplete="list" aria-controls="typeahead_list_u_0_j"
aria-expanded="false" aria-haspopup="true" aria-label=
"Write a birthday wish on his Timeline..." class=
"enter_submit uiTextareaNoResize uiTextareaAutogrow uiStreamInlineTextarea inlineReplyTextArea mentionsTextarea textInput"
cols="48" id="u_0_k" name="message_text" placeholder=
"Write a birthday wish on his Timeline..." role="textbox" title=
"Write a birthday wish on his Timeline..."></textarea>
</div>
My code:
textbox = driver.find_element_by_name('message_text')
textbox.send_keys('Happy Birthday! ')
The webpage I'm working on is Facebook. Birthdays
source to share
So, I was finally able to find the element and fix the above error by looking at the page source.
print(driver.page_source)
The source of the page showed that the name of the element message
, not message_text
. However, the validation element in the browser still shows message_text
.
source to share
This question has been answered, but the doc links the answer points to are out of date, so here is the updated "switch to" / switch commands selenium docs
You need to use this command to switch your driver so that it works in the correct window / frame / etc.
Check which windows are open by running: first run driver.getWindowHandles();
to bring back a set of all windows
Then use driver.switchTo().window(handle);} #if switching to another window
or driver.switchTo().frame("yourframename");} #if switching to a frame
or driver.switchTo().alert(); #if switching to a popup
Hope it helps
source to share