How to use element_contains method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

Auto_xpath_2.py

Source:Auto_xpath_2.py Github

copy

Full Screen

1"""2@Project :study 3@Author : 文跃锐(yuerwen)4@University:东莞理工学院5@Time : 2022/01/076@File :Auto_xpath_1.py7"""8# 根据属性来选择9# 语法:[@属性名 = ‘属性值’]10from selenium.webdriver.common.by import By11from selenium import webdriver12wd = webdriver.Chrome()13# 创建等待时间14wd.implicitly_wait(5)15# 打开指定网页地址16web_files = r'http://cdn1.python3.vip/files/selenium/test1.html'17wd.get(web_files)18# -- 根据id属性选择选择 //*[@id='west']19element = wd.find_element(By.XPATH,"//*[@id='west']")20print(element.get_attribute('outerHTML'))21# -- 根据class属性选择 可以这样 //select[@class='single_choice']22element = wd.find_element(By.XPATH,"//select[@class='single_choice']")23print(element.get_attribute('outerHTML'))24# -- 根据其他属性 //*[@multiple]25element = wd.find_element(By.XPATH,"//*[@multiple]")26print(element.get_attribute('outerHTML'))27# -- 属性值包含字符串28# 要选择 style属性值 包含 color 字符串的 页面元素 ,可以这样 //*[contains(@style,'color')]29# -- 属性包含字符串 contains(@属性名,'要包含的属性名')函数30element_contains = wd.find_element(By.XPATH,"//*[contains(@style,'color')]")31print(element_contains.get_attribute('outerHTML'))32# 要选择 style属性值 以 color 字符串 开头 的 页面元素 , 可以这样 //*[starts-with(@style,'color')]33# -- 属性以指定字符串开头 starts-with(@属性名,'指定的属性名')34element_starts_with = wd.find_element(By.XPATH,"//*[starts-with(@style,'color')]")35print(element_starts_with.get_attribute('outerHTML'))36'''37//*[ends-with(@style,'color')],38但是,很遗憾,这是xpath 2.0 的语法 ,目前浏览器都不支持39'''40# element_starts_end = wd.find_element(By.XPATH,"//*[end-with(@style,'color')]")41# print(element_starts_end.get_attribute('outerHTML'))...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...45 else:46 raise HTTPException(status_code=400, detail='Bad Request')47 return {"elements": elements}48@app.get("/element_contains")49async def element_contains(string: str):50 arr = []51 for element in elements:52 if string.lower() in element.lower():53 arr.append(element)54 return {f"elements that have {string}": arr}55@app.get("/list")56async def get_list():57 return {"result": elements}58@app.post("/calculator")59async def calculator(calculator: Calculator):60 expr = calculator.expr61 arr = expr.split(',')62 num1 = int(arr[0])63 num2 = int(arr[2])...

Full Screen

Full Screen

set_discard_remove_pop.py

Source:set_discard_remove_pop.py Github

copy

Full Screen

1number_elements=int(input())2element_contains=input().split()3element_contains=set(map(int,element_contains))4number_commands=int(input())5for n in range(number_commands):6 command=input().split()7 if command[0]=='pop':8 element_contains.pop()9 elif command[0]=='remove' and int(command[1]) in element_contains:10 element_contains.remove(int(command[1]))11 elif command[0]=='discard':12 element_contains.discard(int(command[1]))13if len(element_contains)==0:14 print('0')15else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lettuce_webdriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful