コード例 #1
0
def check_box_demo2():
    driver.get("http://ui.yansl.com/#/checkbox")
    sleep(2)
    check_box = driver.find_element_by_xpath("//span[@class='el-checkbox__inner']")
    check_box.click()
    if (not check_box.is_selected()):# 判断条件
        check_box.click()
コード例 #2
0
def select_demo3():
    driver.get("http://ui.yansl.com/#/select")
    select = driver.find_element_by_xpath("//input[@name='item4']")
    sleep(2)
    selecti = driver.find_element_by_xpath("(//li[@name='option4'])[2]")
    selecti.click()
    sleep(1)
コード例 #3
0
def check_box_demo():
    driver.get("http://ui.yansl.com/#/checkbox")
    sleep(2)
    check_box = driver.find_element_by_xpath("//input[@value='1']")
    check_box.click()
    if (not check_box.is_selected()):
        check_box.click()
コード例 #4
0
def check_box_demo4():
    driver.get("http://ui.yansl.com/#/checkbox")
    sleep(2)
    check_box = driver.find_element_by_xpath("//span[text()='上海']/../span/span")
    check_box.click()
    if (not check_box.is_selected()) : # 判断条件
        check_box.click()
コード例 #5
0
def select_demo():
    driver.get("http://ui.yansl.com/#/select")
    sleep(2)
    select = driver.find_element_by_xpath("//input[@name='item2']")
    select.click()
    sleep(1)
    lll = driver.find_element_by_xpath("//span[text() = '黄金糕2']")
    lll.click()
コード例 #6
0
def cascader_demo():
    driver.get("http://ui.yansl.com/#/cascader")
    sleep(2)
    driver.find_element_by_xpath("//label[text()='hover触发']/../div//input").click()
    sleep(2)
    zu_jian=driver.find_element_by_xpath("(//span[text()='组件'])[last()]")
    actions = ActionChains(driver)
    actions.move_to_element(zu_jian).perform()
コード例 #7
0
def input_demo2():
    # 查找元素的方法有:id(选择使用),name,class,tag_name,xpath(推荐),css_selector
    driver.get("http://ui.yansl.com/#/input")
    sleep(2)
    text = driver.find_element_by_name("t2")
    # 清空
    text.clear()
    # 填值
    text.send_keys("你好")
コード例 #8
0
def select_demo2():
    driver.get("http://ui.yansl.com/#/select")
    sleep(2)
    select = driver.find_element_by_xpath("//input[@name='item3']")
    select.click()
    sleep(1)
    select2 = driver.find_element_by_xpath("(//span[text()='双皮奶'])[5]")
    select2.click()
    sleep(1)
    select2 = driver.find_element_by_xpath("//form")   # 要点击空白的地方定位
    select2.click()
コード例 #9
0
def input_demo():
    # 查找元素的方法有:id(选择使用),name,class,tag_name,xpath(推荐),css_selector
    driver.get("http://ui.yansl.com/#/input")
    sleep(2)
    text = driver.find_element_by_name("t1")
    # 清空
    text.clear()
    # 填值
    text.send_keys("你好")

    # 组合键 先ctrl+a 全选然后抬起键盘然后删除最后执行
    actions = ActionChains(driver)
    actions.click(text).key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL).send_keys(Keys.BACKSPACE).perform()
コード例 #10
0
def upload_demo():
    driver.get("http://ui.yansl.com/#/upload")
    sleep(1)
    # upload1 = driver.find_element_by_xpath("//label[text()='原始上传']/../div/input")
    # upload1.send_keys("C:\\Users\\Administrator\\Desktop\\replay_pid728.log") # 每个斜杠都要加\转义

# send_key 上传方法只支持input标签,type属性为file的
    file=driver.find_element_by_xpath("(//span[text()='点击上传'])[1]")
    file.click()
    autoit.win_wait("打开", 10)
    sleep(2)
# autoit.control_send("打开", "Edit1", os.path.abspath(file_path))

    autoit.control_set_text("打开", "Edit1","C:\\Users\\Administrator\\Desktop\\replay_pid728.log" )
    sleep(2)
    autoit.control_click("打开", "Button1")
コード例 #11
0
def open_links():
    driver.get(robots)

    driver.execute_script("window.open('');")
    driver.switch_to.window(driver.window_handles[1])
    driver.get(sitemap)

    driver.execute_script("window.open('');")
    driver.switch_to.window(driver.window_handles[2])
    driver.get(url)
コード例 #12
0
store_url = list(search_store())
# var_regex = r"\b(?=\w)" + re.escape(TEXTO) + r"\b(?!\w)"

store_url_index = input(
    "Please type the store URL index; index starts from 0 and numbered only:")
store_url_index = int(store_url_index)
print("The selected store URL is: " + store_url[store_url_index])
'''
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[3])
driver.get(store_url[store_url_index])
'''

driver = webdriver.Firefox()
driver.get(store_url[store_url_index])


def respo():
    print("Current Browser URL is: " + driver.current_url)
    try:
        api_calls = []
        for requ in driver.requests:
            res = requ.response.headers['Content-Type']
            if res == "application/json" or res == "application/json; charset=utf-8":
                api_calls.append(requ.url)
                print(requ.url)
    except:
        print(
            "Some headers does not have the Content-Type defined so ignoring then"
        )
        soup = BeautifulSoup(res.content,'html.parser')
                
        titles = soup.select('h3 > a')
        subs = soup.select('.slp > span')               
                
        for sub in subs:
            print(sub.text)
            
        i = i + 10
        
        
        
import requests
import driver

driver.get("https://twitter.com/login")
url = "https://twitter.com/login"


element = driver.find_element_by_id("session[username_or_email]")  




payload = { 'session[username_or_email]': '*****@*****.**', 'session[password]': 'dlwnsgk94!'}
r = requests.post(url, data=payload)

r = requests.post("https://www.naver.com/")
        
res = requests.get('https://twitter.com/Bo1210Cap/following')
res = requests.get('https://www.naver.com/')
コード例 #14
0
# -*- coding: utf-8 -*-
import requests as rq
import driver
from bs4 import BeautifulSoup as BS
from selenium import webdriver
import time

pov = int(input("установите повторения: "))
pov_plus = 0
driver = webdriver.Chrome(
    "C:/Users/ludol/Desktop/stepan/chrome_driver/chromedriver")
driver.get("https://www.b17.ru")
while pov_plus < pov:
    try:
        driver.find_element_by_id("index_list_next").click()
    except (BaseException):
        pass
    last_height = driver.execute_script("return document.body.scrollHeight")
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(1.5)
    new_height = driver.execute_script("return document.body.scrollHeight")
    last_height = new_height
    pov_plus += 1
print("парсинг закончен, страница сохраняется")
html_source = driver.page_source


def obrabotka(obr):
    OnOff = False
    output = []
    for i in range(len(obr)):
コード例 #15
0
import driver as driver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
driver = Chrome()

with Chrome() as driver:
    driver.get("http://automationpractice.com/index.php")
    driver.maximize_window()
    url = driver.current_url
    title = driver.title
    print(title)
    print(url)

    #assert 'The Internet' in driver.title
    departments = driver.find_element_by_id("block_top_menu")
    #time.sleep(10)
    women_department = driver.find_element_by_class_name("sf-with-ul").click()
    time.sleep(3)
    ActionChains(driver).move_to_element(
        driver.find_element_by_xpath(
            "//*[@id='center_column']/ul/li[6]")).perform()
    time.sleep(3)
    previous_dress_name = driver.find_element_by_xpath(
        "//*[@id='center_column']/ul/li[6]/div/div[2]/h5/a").text
    print(previous_dress_name)
    previous_dress_price = driver.find_element_by_xpath(
        "//*[@id='center_column']/ul/li[6]/div/div[1]/div/div[2]/span").text
    print(previous_dress_price)
    ActionChains(driver).move_to_element(
コード例 #16
0
ファイル: waitDemo.py プロジェクト: appjha/selenium_repo
import time

import driver as driver
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import by
from selenium.webdriver.common.by import by

s = Service("C:\\chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.get("https://rahulshettyacademy.com/seleniumPractise/#/")
driver.find_element("css selector", "input.search-keyword").send_keys("ber")
time.sleep(4)
#count= len(driver.find_element_by_xpath("//div[@class='products']/div"))
#assert count==3
button = driver.find_element_by_xpath(
    "//div[@class='product-action']/button").click()
#b=driver.find_element_by_xpath("//div[@class='product-action']/button")
print("hiiiiiii:", button)
#for buttons in button:
# buttons.click()

driver.find_element_by_css_selector("img[alt='Cart']").click()
###driver.find_element_by_xpath("//button[text()='PROCEED TO CHECKOUT']/").click()
##hello
コード例 #17
0
def insert_img(driver, file_name):
    base_dir = os.path.dirname(os.path.dirname(__file__))
    #base_dir = str(base_dir)
    base_dir = base_dir.replace("\\", "/")
    base_dir = base_dir.split('/test_case')[0]
    file_path = base_dir + "/report/image/" + file_name
    driver.get_screenshot_as_file(file_path)


#获取最新的测试报告,用于发送测试报告邮件
def new_report(file_path):
    files = os.listdir(file_path)
    f_times = []
    for f in files:
        if os.path.splitext(file_path + f)[1] == '.html':
            f_time = os.path.getmtime(file_path + f)
            f_times.append((f_time, f))

    return sorted(f_times)[-1][1]


if __name__ == '__main__':
    sys.path.append(
        "D:\python_script\selenium_auto\mztestpro\mztestpro\bbs\test_case\models"
    )
    print(sys.path)
    import driver
    driver = driver.browser()
    driver.get("http://www.baidu.com")
    insert_img(driver, "baidu.jpg")
    driver.quit()
import urllib.request
import os
import driver as driver
import requests
from bs4 import BeautifulSoup
from selenium import webdriver as wd
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import re
import csv

driver = wd.Chrome('../webdriver/chromedriver.exe')

driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')

time.sleep(3) #웹 페이지 로드를 보장하기 위해 3초 쉬기

#

id = 'gg__heon'
password = '******'
id_input = driver.find_elements_by_css_selector('#react-root > section > main > div > article > div > div > div > form > div > div > label > input')[0]
id_input.send_keys(id)
password_input = driver.find_elements_by_css_selector('#react-root > section > main > div > article > div > div > div > form > div > div > label > input')[1]
password_input.send_keys(password)
password_input.submit()

time.sleep(5)
コード例 #19
0
ファイル: main.py プロジェクト: AlexKJones/Reimbursment
import driver as driver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.webelement import WebElement

from pages.reimbursment_home import Reimbursment
# WebElement = driver.find_element_by_id("q")
driver: WebDriver = webdriver.Chrome(
    "/Users/alexjones/Desktop/RevatureTraining/chromedriver")

main_page = Reimbursment(driver)

try:
    # Login User That Created Request
    driver.get("file:///Users/alexjones/Desktop/RevatureTraining/reimbursment-client/home.html?")
    sleep(1)
    main_page.login_name_field().send_keys("5")
    sleep(2)
    main_page.login_name_button().send_keys(Keys.ENTER)
    sleep(2)
    nameo = driver.find_element_by_id("name")
    nameo = nameo.text
    assert nameo == "Giorno Giovanna"

    # Get Request Data
    main_page.request_name_field().send_keys("5")
    main_page.request_id_field().send_keys("1")
    sleep(1)
    main_page.view_request().send_keys(Keys.ENTER)
    sleep(3)
コード例 #20
0
from select import select

import driver as driver
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('C:\servers\chromedriver.exe')
driver.get('https://support.google.com/mail/answer/56256?hl=en')

driver.find_element_by_css_selector("a[class='action-button']").click()
driver.implicitly_wait(10)
d = driver.find_elements(By.CSS_SELECTOR, "input[id='firstName']")
d.send_keys("bhargav")

#d.send_keys("bhargav")

# dr1=select(dr)
# #dr1.select_by_value()
# print(dr1.options)
# print(len(dr1.options))
コード例 #21
0
ファイル: test_pytest.py プロジェクト: puluxi/polaris-uitest
import driver as driver
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import  random
import time

from selenium.webdriver.remote.webelement import WebElement
driver = webdriver.Chrome()
driver.get("http://172.16.6.108/user/login")
driver.maximize_window()
driver.find_element_by_id("login-form_username").send_keys("admin")
driver.find_element_by_id("login-form_password").send_keys("yjg123456")
driver.find_element_by_xpath("//button[@type='submit']").click()
time.sleep(5)
driver.find_element_by_xpath("//span[text()='权限管理']/..").click()
time.sleep(5)
driver.find_element_by_xpath("//span[text()='用户管理']/../..").click()
time.sleep(5)
driver.find_element_by_xpath("//div[@class='ant-card ant-card-middle']//button[@class='ant-btn ant-btn-primary']").click()
time.sleep(5)
usernameNO = str(random.randint(0,10000))
loginnameNO = str(random.randint(0,10000))
phoneNO = str(random.randint(9999999,100000000))
username = "******" + usernameNO
loginname = "NovaAuto" + loginnameNO
phonenumer = "187" + phoneNO

driver.find_element_by_id("userName").send_keys(username)
time.sleep(1)
driver.find_element_by_xpath("//input[@placeholder='请输入手机号码']").send_keys(phonenumer)
time.sleep(1)
コード例 #22
0
ファイル: chrome_demo.py プロジェクト: yujiao7/ui-jichu
#__mtime__ = '2019/9/17'
from time import sleep

import driver as driver
from selenium import webdriver

# 打开浏览器
driver=webdriver.Chrome("../chromedriver-v77/chromedriver.exe")


# 调整浏览器窗口大小
driver.maximize_window() # 窗口最大化一般用这个
# driver.set_window_size(1600,900) # 括号里面跟分辨率

# 打开网址
driver.get("http://api.yansl.com:8080/swagger-ui.html#!")
sleep(2)
driver.get("https://www.baidu.com/")
sleep(2)
driver.get("https://www.taobao.com/")


# 后退
driver.back()
sleep(2)

# 前进
driver.forward()
sleep(2)

# 刷新
コード例 #23
0
def time_demo():
    driver.get("http://ui.yansl.com/#/dateTime")
    time_demo= driver.find_element_by_xpath('//input[@placeholder="任意时间"]')
    time_demo.clear() # 清除
    time_demo.send_keys("18:50:01") # 写入值
コード例 #24
0
 def test_login(self, test_setup):
     driver.get("https://www.aoe.com")
     time.sleep(1)
コード例 #25
0
def test_deleting (driver):
    app.go_to_home_page()
    app.login (User.Admin())driver.get("http://localhost/php4dvd/")
    deleting (driver)
    assert app.movie_is_deleted
    logout(driver)
コード例 #26
0
def radio_demo2():
    driver.get("http://ui.yansl.com/#/radio")
    sleep(2)
    sex = driver.find_element_by_xpath("//input[@value='1']")
    sex.click()
コード例 #27
0
def radio_demo33():
    driver.get("http://ui.yansl.com/#/radio")
    sleep(2)
    sex = driver.find_element_by_xpath("(//span[@class='el-radio__inner'])[2]")
    sex.click()
コード例 #28
0
# coding=utf-8
import driver as driver
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.remote.webelement import WebElement
import re
from selenium.webdriver.support.color import Color


driver = webdriver.Chrome(executable_path=r"C:\Users\Dell\PycharmProjects\seleniumwebd\Selenium\drivers\chromedriver")

driver.get("https://www.tui.pl/")

print(driver.title)
print(driver.current_url)

driver.find_element(By.CLASS_NAME, "my-tui").click()
time.sleep(2)

driver.switch_to.window(driver.window_handles[1])

email = driver.find_element(By.ID, "email")
password = driver.find_element(By.ID, "pass")

email.clear()
password.clear()

rgb = email.value_of_css_property('background-color')
hex = Color.from_string(rgb).hex
コード例 #29
0
from selenium.webdriver.common.keys import Keys
import re
import time

URL = 'https://www.asos.com/men/outlet/shoes-trainers/cat/?cid=27437&nlid=mw%7Coutlet%7Cshop%20by%20product&page=1'

headers = {
    "User-Agent":
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36'
}

# driver = webdriver.Chrome()
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.implicitly_wait(10)  # seconds

driver.get(URL)

s = 'Nike Running x Cody Hudson Epic React Phantom trainers in white'

inputElement = driver.find_element_by_xpath('//*[@id="chrome-search"]')
inputElement.send_keys(s)
inputElement.submit()
driver.refresh()

try:
    name = driver.find_element_by_xpath(
        '/html/body/main/div[1]/section[1]/div/div[2]/div[2]/div[1]/h1').text
except selenium.common.exceptions.StaleElementReferenceException:
    print('Full xpath didn\`t work')
finally:
    name = driver.find_element_by_xpath(
コード例 #30
0
ファイル: scrolling.py プロジェクト: barghavareddy/selenium
from select import select
from telnetlib import EC
from selenium.webdriver.support import expected_conditions
import driver as driver
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome('C:\servers\chromedriver.exe')
driver.get('https://www.swiggy.com')
driver.maximize_window()
# wait=WebDriverWait(driver,10)
# ele=wait.until(expected_conditions.element_to_be_clickable(driver.find_element_by_xpath("//*[@id='city-links']/div/ul[2]/li[112]/a").click()))
driver.find_element_by_xpath(
    "//*[@id='city-links']/div/ul[2]/li[112]/a").click()
driver.back()
driver.find_element_by_partial_link_text("Team").click()
hand = driver.window_handles
for i in hand:
    driver.switch_to.window(i)
    print(driver.title)

print("exit-----------")
コード例 #31
0
# %% [Markdown]
# > what kind of file can we get?

# %%
url0 = 'https://img4.goodfon.com/original/2400x1380/1/b1/wlop-ghostblade-art-devushka.jpg'
url = 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1906469856,4113625838&fm=26&gp=0.jpg'
res = requests.get(url)
with open('strwberry.jpg', 'wb') as f:
    f.write(res.content)
print(res.status_code)

# %% [markdown]
# > selenium
# > webdriver chrome
# used for dynamic website
# https://www.jianshu.com/p/dd848e40c7ad
# http://chromedriver.storage.googleapis.com/index.html?path=80.0.3987.16/

# %%
driver = webdriver.Chrome

# %%
driver.get('https://www.toutiao.com/')
print(driver.status_code)

# %%
file = open(
    r'I:\Programming\Python\python-workspace\Workspace for Python\studying file\Spider\toutiao.html',
    'w')
file.write(driver.page_source)