Best Python code snippet using lettuce_webdriver_python
Auto_xpath_2.py
Source:Auto_xpath_2.py
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'))...
main.py
Source:main.py
...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])...
set_discard_remove_pop.py
Source:set_discard_remove_pop.py
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:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!