我有一个填写Facebook注册的方法,并应按“创建一个帐户”按钮。它接缝,它创立按钮,但由于不明原因,无法点击按钮,它找到按钮,但无法点击它
代码:
<button type="submit" class="_6j mvm _6wk _6wl _58mi _3ma _6o _6v" name="websubmit" id="u_0_s">Create Account</button>
,我的方法是:
def submit_new_account_form(self, **credentials):
firstname = self.driver.find_element_by_css_selector(self.__first_name_field_css)
lastname = self.driver.find_element_by_css_selector(self.__last_name_field_css)
number_or_email = self.driver.find_element_by_css_selector(self.__mobile_number_or_email_field_css)
newpass = self.driver.find_element_by_id(self.__new_password_field_id)
maleradio = self.driver.find_element_by_css_selector(self.__male_radio_css)
femaleradio = self.driver.find_element_by_css_selector(self.__female_radio_css)
submit_button = self.driver.find_element_by_id(self.__create_account_button_id)
if submit_button:
print ("submit button found")
if maleradio:
print("maleradio found")
if femaleradio:
print ("femaleradio found")
#firstname.clear()
if credentials['first_name']:
firstname.send_keys(credentials['first_name'])
#lastname.clear()
if credentials['last_name']:
lastname.send_keys(credentials['last_name'])
#number_or_email.clear()
if credentials['phone_or_email']:
number_or_email.send_keys(credentials['phone_or_email'])
re_enter_email_field = WebDriverWait(self.driver, 10).until(
expected_conditions.presence_of_element_located((By.CSS_SELECTOR,self.__re_enter_new_email_field_css)))
re_enter_email = self.driver.find_element_by_css_selector(self.__re_enter_new_email_field_css).send_keys(
credentials['phone_or_email'])
#newpass.clear()
if credentials['newpass']:
newpass.send_keys(credentials['newpass'])
if credentials['sex'] == 'male':
maleradio.click()
if credentials['sex'] == 'female':
femaleradio.click()
submit_button.click()
if submit_button.click():
print('submit button clicked')
每个I运行脚本时
提交按钮点击不出现,出现错误:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
的按钮不可见点击它。你需要等到它真的出现,否则硒会升高。你确定该按钮在页面上始终可见吗?或者在你填写表格后出现? – user3012759