python selenium某里国际站网站注册登录验证问题

要先看好有没有ifram,有的话要切换才可以实现。比如我这里做的是阿里巴巴国际站的登录,要逐级依次切入。注册页面反而没有ifram。

driver.switch_to_frame("alibaba-login-box")#切进大的ifram driver.switch_to_frame("baxia-dialog-content")#切进小的ifram #这里写操作代码 driver.switch_to_default_content()#切出来

1、滑动滑块

import time from selenium import webdriver from selenium.webdriver import ActionChains
 # 定位第一个滑块 dragger = driver.find_elements_by_id("nc_1_n1z")[-1] action = ActionChains(driver) # 对滑块按下鼠标左键不放 action.click_and_hold(dragger).perform() for index in range(20): try: # X每次移动2个像素,Y为0。平行移动鼠标 action.move_by_offset(71, 0).perform() except UnexpectedAlertPresentException: break
 draggable = driver.find_element_by_id('nc_1__scale_text') # 滚动指定元素位置 driver.execute_script("arguments[0].scrollIntoView();", draggable) time.sleep(2) ActionChains(driver).click_and_hold(draggable).perform() # 拖动 ActionChains(driver).move_by_offset(xoffset=247, yoffset=0).perform() ActionChains(driver).release().perform() time.sleep(3)

2、登录后要验证涂抹元素使其显示出两只小鸡

想了一个晚上,发现用一个for循环,去滑动n次,随机取滑动范围值,滑它100次200次我就不信涂不出两只小鸡。注意要看元素尺寸大小,取值范围太小滑不出来

 # 鼠标往右上方横向纵向各随机移动 element = driver.find_element_by_css_selector("[id='nc_1_cover']") ActionChains(driver).click_and_hold(element) for dd in range(100): print(dd) result1 = random.randint(-300, 300) result2 = random.randint(-50, 50) ActionChains(driver).drag_and_drop_by_offset(element, result1, result2).perform() 

原文链接:https://blog.csdn.net/weixin_44740756/article/details/123341714?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166868812616800192219927%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166868812616800192219927&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-6-123341714-null-null.nonecase&utm_term=%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4%E5%9B%BD%E9%99%85%E7%AB%99

未经允许不得转载/侵删:AlibabaTop工作室 » python selenium某里国际站网站注册登录验证问题

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址