"I am new to selenium python and trying to learn" I have added if condition and also while loop but looks like I am getting lost with the indentations of it . Its giving me for the below line::
driver.find_element_by_xpath("//div[@class='v-horizontallayout v-horizontallayout-x-horizontal-layout x-horizontal-layout']//Span[contains(text(),'Post')]").click()
Error is: Unable to locate element: (but this was working fine before)
Below is my code :
if Currency [0] == '€':
print("Hello, I am printing €, as I am in Euro til")
driver.find_element_by_xpath(
"//div[@class='v-customcomponent v-customcomponent-gk-action-bar gk-action-bar v-customcomponent-portal-menu-actionbar portal-menu-actionbar']//Span[contains(text(),'Drawer')]").click()
driver.find_element_by_xpath(
"//div[@Class='v-tree-node-caption']//Span[contains(text(),'Drawer Accounts')]").click()
driver.switch_to.frame(1)
print("I am inside frame")
wait.until(EC.element_to_be_clickable((By.XPATH, ".//span[text()='Account']"))).click()
print("I have cliked on Account")
time.sleep(2)
current_loan = driver.find_element(By.XPATH,"//div[contains(text(),'Current Loan/Change Amount')]/ancestor::div[contains(@class,'horizontallayout')]/../../following-sibling::div/descendant::input").get_attribute('value')
print("This is your current loan: ", current_loan)
new_loan = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@class='v-textfield v-textfield-text-align-right text-align-right']")))
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@class='v-textfield v-textfield-text-align-right text-align-right']")))
val = "1000"
new_loan.send_keys(val)
actual_val = int(val)
const_val = 500
post = driver.find_element(By.XPATH, ("//span[contains(text(),'Post')]"))
post.click()
time.sleep(2)
i = 0
while True:
try:
if(len(driver.find_elements(By.XPATH, "//span[text()='Close']"))) > 0:
print("Alert is visible", i)
i = i + 1
print(i)
time.sleep(.5)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'Close')]"))).click()
time.sleep(.5)
new_loan.clear()
time.sleep(.5)
keys_to_send = actual_val - const_val
time.sleep(.5)
new_loan.send_keys(str(keys_to_send))
time.sleep(.5)
post.click()
const_val = const_val + 10
time.sleep(.5)
if const_val >= 1000:
break
else:
print("post must have worked")
break
except:
print('Something went wrong in code')
break
print("I am out of while")
time.sleep(2)
driver.find_element_by_xpath("//div[@class='v-horizontallayout v-horizontallayout-x-horizontal-layout x-horizontal-layout']//Span[contains(text(),'Post')]").click()
# actual_amount_list_size = len(driver.find_elements_by_xpath("//div[text()='Actual Amount']/ancestor::div/following-sibling::div/descendant::input"))
# print(actual_amount_list_size)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src*='p://gksdc-tst.pvhcorp.com']")))
actual_amount_list_size = len(driver.find_elements_by_xpath("//div[text()='Actual Amount']/ancestor::div/following-sibling::div/descendant::input"))
print(actual_amount_list_size)
i = 1
difference_amount = []
for a_amount in driver.find_elements(By.XPATH,"//div[text()='Actual Amount']/ancestor::div[@class='v-table-header-wrap']/following-sibling::div/descendant::input"):
ActionChains(driver).move_to_element(a_amount).perform()
# ele_1= wait.until(EC.element_to_be_clickable((By.XPATH, f"(//div[text()='Actual Amount']/ancestor::div[@class='v-table-header-wrap']/following-sibling::div/descendant::input)[{i}]")))
time.sleep(.5)
a_amount.send_keys('0')
time.sleep(.5)
a_amount.send_keys(Keys.RETURN)
time.sleep(.5)
ActionChains(driver).move_to_element(wait.until(EC.visibility_of_element_located((By.XPATH,f"//div[text()='Difference']/ancestor::div[@class='v-table-header-wrap']/following-sibling::div/descendant::table/descendant::tr[{i}]/td[5]")))).perform()
print(wait.until(EC.visibility_of_element_located((By.XPATH,f"//div[text()='Difference']/ancestor::div[@class='v-table-header-wrap']/following-sibling::div/descendant::table/descendant::tr[{i}]/td[5]"))).text.replace('-', '').replace(',', ''))
difference_amount.append(wait.until(EC.visibility_of_element_located((By.XPATH,f"//div[text()='Difference']/ancestor::div[@class='v-table-header-wrap']/following-sibling::div/descendant::table/descendant::tr[{i}]/td[5]"))).text.replace('-', '').replace(',', ''))
time.sleep(.5)
i = i + 1
Aucun commentaire:
Enregistrer un commentaire