python - 我收到错误:如果我更新购物车,则无法将字符串转换为浮点数
问题描述
重建步骤:
1.Go to http://practice.automationtesting.in/
2.Click on add to basket
3.Then view basket
4.Change the quantity to 2
5.Click on Update Basket
6.Save price before coupon
6.Use coupon code "krishnasakinala"
7.Click on Apply Coupon button
8.save price after coupon is applied
9. strip both before and after coupon price of rupee symbol
10.convert to float and assert pricebeforecoupon > priceaftercoupon
代码:
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as W
from selenium.webdriver.support import expected_conditions as E
driver: WebDriver = webdriver.Chrome(executable_path=r"C:\Users\Ratna
Sinha\Downloads\chromedriver_win32\Chromedriver.exe")
driver.maximize_window()
url= "http://practice.automationtesting.in"
driver.get(url)
wait_timeout = 20
wait_variable = W(driver,wait_timeout)
driver.find_element_by_xpath("//a[@data-product_id='160']").click()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//a[@class = 'added_to_cart wc-forward']"))).click()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).clear()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).send_keys(2)
wait_variable.until(E.element_to_be_clickable((By.NAME, "update_cart"))).click()
wait_variable.until(E.presence_of_element_located((By.CSS_SELECTOR,'[class="blockUI blockOverlay"]')))
wait_variable.until(E.staleness_of( driver.find_element_by_css_selector('[class="blockUI blockOverlay"]')))
pricebefcoupon = driver.find_element_by_xpath("//strong/span").text
driver.find_element_by_name("coupon_code").send_keys("krishnasakinala")
driver.find_element_by_name("apply_coupon").click()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//div[@class='cart-collaterals']/div/div[@class ='blockUI blockOverlay']")))
wait_variable.until(E.staleness_of(driver.find_element_by_xpath("//div[@class='cart-collaterals']/div/div[@class ='blockUI blockOverlay']")))
priceafcoupon = driver.find_element_by_xpath("//strong/span").text
str = pricebefcoupon
str = str.strip('₹')
print(str)
str1 = priceafcoupon
str1 = str1.strip('₹')
print(str1)
assert float(str1) < float(str)
但是,如果我没有通过注释掉以下代码来更新购物车,它工作正常。
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).clear()
wait_variable.until(E.presence_of_element_located((By.XPATH,"//input[@type='number']"))).send_keys(2)
wait_variable.until(E.element_to_be_clickable((By.NAME, "update_cart"))).click()
wait_variable.until(E.presence_of_element_located((By.CSS_SELECTOR,'[class="blockUI
blockOverlay"]')))
wait_variable.until(E.staleness_of( driver.find_element_by_css_selector('[class="blockUI
blockOverlay"]')))
解决方案
推荐阅读
- ios - 如何在Swift中从一个点到下一个点画一条线
- xamarin - Azure DevOps Pipeline VsTest:错误消息:System.IO.FileNotFoundException:无法加载文件或程序集“Mono.Android”
- python - 如何在索引字典时修复请求超时
- react-native - 存在“dispatch”关键字时未调用函数
- python - 上下文不会被新值覆盖
- javascript - 我必须使用 javascript 正则表达式编写一个函数来从变量中获取特定的输出字符串
- ios - SiriKit iOS13 - Siri 对话框未出现
- php - 具有爆炸功能的PHP脚本问题
- r - 尝试从 API 获取数据
- wordpress - 添加过滤器以根据组合中的属性名称自动更改产品价格(woocommerce)