简体   繁体   中英

How to click the login button with selenium?

How do I click the submit button in this form with selenium?

HTML

<form name="loginform" method="post" action="https://ap.hongik.ac.kr/login/LoginExec3.php"
  onsubmit="chkFrontLogin();return false;">
  <div class="t">
    <div class="r">
      <div class="c q1">
        <div class="id"><label>id</label><input type="text" name="USER_ID"></div>
        <div class="pw"><label>password</label><input type="password" name="PASSWD"></div>
      </div>
      <div class="c q2">
        <button type="submit" class="button submit"><span class="lbl">login</span></button>
      </div>
    </div>
  </div>
  <input type="hidden" name="Refer" value="http://gw.hongik.ac.kr/index.php">
</form>

My code

driver.find_element_by_xpath("//div[@id='main']/div[@class='align']/table/tbody/tr/td/form/button").click()

I used xpath and searched stackoverflow.

I cannot find a clue for the error(NosuchElementException).

您的按钮具有一个名为“类型”的属性,您可以使用该属性来查找它:

driver.find_element_by_xpath('//button[@type="submit"]').click()

Try this instead

driver.find_element_by_xpath("/html/body/form/div/div/div[2]/button/span")

An easy way to locate the correct xpath is to right-click and [Inspect] element in Chrome, then right-click the HTML code segment and [Copy] -> [Copy XPath].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM