页面的源代码如下所示:
<div class="inner1">
<!--<h4>LOGIN:</h4>-->
<div class="SubID" style="float:left; margin-left:30px;">
<label for="ID">Your <span class="subscriberID">Subscriber ID</span>:</label>
<br>
<input name="ID" size="34" maxlength="20" type="text" style="width:233px !important;">
</div>
<div class="SubName">
<label for="LASTNAME">Your <span class="lastName">Last Name</span> OR <span class="lastName">Company</span>:</label>
<br>
<input name="LASTNAME" size="34" maxlength="50" type="text" style="width:233px !important;">
</div>
<input type="hidden" name="file" value="" />
<div class="SubButton1 spaceBelow">
<input name="submitbtn" type="submit" value="Submit">
</div>
<p class="spaceBelow Clear" style="text-align:center;">The above
information can be obtained from your magazine label.<br>
A sample label is shown below.</p>
<p class="spaceBelow Clear" style="text-align:left;"><a href="idlookup.asp">Forgot
your Subscriber ID?</a></p>
</div>
<!--END INNER1 -->
我可以模拟输入&#39; SubID&#39;和&#39;子名称&#39;如下:
user_name = browser.find_element_by_class_name('SubID > input[type="text"]')
user_name.send_keys(user)
password = browser.find_element_by_class_name('SubName > input[type="text"]')
password.send_keys(pwd)
我使用以下代码来模拟点击提交按钮,但它是失败的:
submit = browser.find_element_by_class_name('"SubButton1 spaceBelow" > input[type="submit"]')
submit.click()
我收到了错误:
InvalidSelectorException: Given css selector expression "."SubButton1 spaceBelow" > input[type="submit"]" is invalid: InvalidSelectorError: '."SubButton1 spaceBelow" > input[type="submit"]' is not a valid selector: "."SubButton1 spaceBelow" > input[type="submit"]"
答案 0 :(得分:0)
请尝试以下代码:
submit = browser.find_element_by_name("submitbtn")
submit.click()
希望它可以帮到你!
答案 1 :(得分:0)
您已经提交了答案,但您也可以使用XPath:
submitBtn = browser.find_element_by_xpath("//input[@name='submitbtn']")
submitBtn.click()
希望它可以帮到你!