Python / Selenium --headless NoSuchElementException

时间:2018-12-10 11:37:54

标签: python-3.x selenium google-chrome-headless

没有无头模式,我可以毫无问题地登录。麻烦从打开(“ --headless”)模式开始,我得到:

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“ method”:“ id”,“ selector”:“ identifierId”}

问了这个问题之后,我被指出了这个解决方案:Log into gmail using Selenium in Python。并尝试了。仍然无法解决无头模式的问题,因为我找不到要单击的第一个元素。

platform=Windows NT 10.0.17134 x86_64  
headless chrome=70.0.3538.110  
chromedriver=2.44.609538   
selenium = 3.141.0  
python = 3.6

我的chromdriver选项:

options = Options()  
options.add_argument('--window-size=1920x1080')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-gpu')
options.add_argument('--no-default-browser-check')
options.add_argument('--no-first-run')
options.add_argument('--test-type')
options.add_argument("--start-maximized")
options.add_argument('--headless')

我要查找的元素:

def login_submit(self):
    driver.get('https://adwords.google.com/um/signin')
    time.sleep(1)
    driver.save_screenshot("test.png")
    time.sleep(1)
    emailElem = driver.find_element_by_id('identifierId')
    actions = ActionChains(driver)
    actions.move_to_element(emailElem).click_and_hold(emailElem)
    driver.execute_script("arguments[0].click();", emailElem)
    actions.send_keys('email').perform()
    emailElem.send_keys(Keys.ENTER)

已截屏并显示了页面。

HTML

<div class="aXBtI Wic03c">
  <div class="Xb9hP">
    <input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Adres e-mail lub telefon" name="identifier" autocapitalize="none" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value="">  
    <div jsname="YRMmle" class="AxOyFc snByac" aria-hidden="true">e-mail</div> 
  </div>  
  <div class="i9lrp mIZh1c"></div>  
  <div jsname="XmnwAc" class="OabDMe cXrdqd Y2Zypf"></div>  
</div>  

我尝试了这种方法NoSuchElementException with headless chrome and selenium。还有一些:

find_element_by_xpath('//input[contains(@name, 'identifier')]')  
or  
driver.find_elements_by_xpath("//*[contains(text(), 'e-mail')]")

没有任何效果。请帮忙。

0 个答案:

没有答案
相关问题