1
<div class="addr_text" style="float:left;border:none;overflow:hidden;width:13px;">
    <input type="input" style="border:none;outline:none;-webkit-appearance:none;width:100%;" aria-labelledby="to_btn" aria-label="填写收件人,多个使用分号隔开" tabindex="1" autocomplete="off">
    <div id="calCC" style="width: 1px; height: 1px; overflow: auto; white-space: nowrap; border: none; margin: 0px; padding: 0px; font-family: Tahoma; font-size: 12px; font-weight: normal; line-height: normal; word-spacing: 0px;">
    </div>
</div>

I tried to use python3 to compose a email. However, I have the problem to find the element where users type the receiver email address.

After inspecting element, I believe it is the input element in the code above. However, the CSS selector always fails to locate it. I also tried the wait method below.

receiverTag = wait.until(EC.visibility_of(browser.find_element_by_css_selector("#toAreaCtrl > div.addr_text > input[type=input]")))

and the output is as follows

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: #toAreaCtrl > div.addr_text > input[type=input]

Please help me solve this problem! Thanks!

Sahil
  • 1,387
  • 14
  • 41
Python Newbie
  • 317
  • 2
  • 9
  • Are you sure that this is an appropriate string to pass to css selector? Can `.find_element_by_css_selector("div.addr_text").text` solve your problem? – oo00oo00oo00 Jun 03 '20 at 18:13

1 Answers1

0

I did not know the element was in a frame. To access the element in a frame, we must first switch to the frame first. I solved issue by adding the following codes. I cannot believe it takes me almost 2 days to find the answer from some else's code. Want to cry!

time.sleep(3)
toFrame = browser.switch_to.frame(browser.find_element_by_id('mainFrame'))
receiver = browser.find_element_by_css_selector("#toAreaCtrl > div.addr_text > input[type=input]").send_keys('xxx@qq.com')
Python Newbie
  • 317
  • 2
  • 9