I'm trying to interact with the field of Klarna Checkout on a website, but I'm not able to change the selected radio buttons nor enter information in the credit card fields. I'm using VS code, Python and selenium webdriver.
The website destination is: https://voltfashion.com/no/functional/kassen/
You need to add an item in order to see the "Klarna checkout section".
It is a Norwegian website.
I have tried some different coding solutions, but none of them worked. I didn't have any problems interacting with the other elements of the website, just the Klarna checkout section. Any suggestions?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Some of the code I've tried:
cardForm = driver.find_element_by_id("cardNumber")
cardForm.send_keys('1234567890987654')
and
inputCC = WebDriverWait(driver, 5).until\
(lambda driver: driver.find_element_by_xpath\
("//input[#id='cardNumber']")
)
inputCC.send_keys("1234567890987654")
Klarna screenshot (Source):
Related
I was having trouble with find elements by XPATH for a selenium script in Python.
Couldn’t understand the problem, i want to identify all of the elements that satisfy my xpath criteria.
So I simply compared the find_elements(By.XPATG, ‘//div’) to the same result when looking at Chrome’s Inspect tool.
The tool says 300+ results for this whereas my programme, which I got to return a count of results, only states 60? Any ideas? looks to be an thing from the browser/site side rather than my code.
Thanks
EDIT added my code:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
import login
print(time.time())
driver.get("WEBSITE URL")
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//body")))
time.sleep(1)
links = driver.find_elements(By.XPATH,'//body')
linklist = len(links)
print(linklist)
This provides a result of around 60 however when '//body' is put in the inspect element tool, it returns 300+
Apologies but the targeted webpage is confidential so I can't post. But suggestions are appreciated so I can investigate.
Does your web page has a scroll? If yes, you may need to deal with scroll bar. Also try different conditions for WebDriverWait, for example EC.visibility_of_all_elements_located or EC.presence_of_all_elements_located
I am trying to learn selenium and i am trying to download an excel file from a drop down menu.
Firstly, i click to button in order to open it and afterwards when i do inspect i am able to get to this part.
I am trying to click this part and download the file.
<span _ngcontent-bke-c150="" class="left-text">Excel</span>
Here is the link to the website: https://survey123.arcgis.com/
I don't think sharing my code would help because i am already stuck at that very specific part. I was able to login to the website through selenium and enter id and password but failed at downloading the excel file.
But here it is
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome()
driver.get("https://survey123.arcgis.com/")
inputElement_user = driver.find_element_by_id("user_username")
inputElement_user.send_keys("myusername")
inputElement_password = driver.find_element_by_id("user_password")
inputElement_password.send_keys("mypassword")
giris_button = driver.find_element_by_id("signIn")
actions = ActionChains(driver)
actions.click(giris_button)
actions.perform()
continue_link = driver.find_element_by_partial_link_text('Rapor')
This might not exactly be the answer but I had also stuck on this point some time ago. I tried this <a href="file/path/or/link/here" download> and it worked.
the download property makes files downloadable, if the href is set properly. hope this works in your problem as well.
I am trying to scrape for car prices from this website:
To get car prices, you should fill out the form and I have to choose from dropdowns using Selenium.
I am using this code to choose from dropdowns:
# Imports
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
year_dropdown = Select(WebDriverWait(driver, 5)
.until(EC.element_to_be_clickable((By.ID, "j_id_3q-carInfoForm-year-selectOneMenu"))))
year_dropdown.select_by_value('2015')
But after I chose the year, it just keeps loading and never stops:
Any suggestions please?
I resolved the issue by using a real chrome driver. I was using chromdriver-manager package and when I removed it and downloaded a real chrome driver, the issue was gone.
I am trying to use Selenium in Python to click on a link to a report on a web page. I have it working up to the point where it opens the page that the report is on, but I am having trouble actually clicking that specific report.
The page has a list of reports all with the same class. This is what I get when I inspect that specific report for example:
<a class="rpt" href="reportConfigRedirect.asp?action=filter&rc_id=181786&letter=">Run with new filters</a>
I have tried:
driver.find_element_by_xpath("xpath")
and this doesn't seem to work, it doesn't do anything once it gets to that page with the report.
Induce WebdriverWait and element_to_be_clickable.Use the following Xpath.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[#class='rpt'][contains(.,'Run with new filters')]")))
element.click()
If unable to click using Webdriver try use javascript executor.
element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[#class='rpt'][contains(.,'Run with new filters')]")))
driver.execute_script("arguments[0].click();",element)
EDITED
element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(.,'Run with new filters')]")))
driver.execute_script("arguments[0].click();",element)
OR
element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(#hef,'reportConfigRedirect.asp?action=filter')][contains(.,'Run with new filters')]")))
driver.execute_script("arguments[0].click();",element)
I'm trying out the selenium framework to learn something about the web browser automation. Therefore, I decided to build an Audi model...
My code so far:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
chrome_driver = webdriver.Chrome(executable_path=r"chromedriver_win32\chromedriver.exe")
chrome_driver.get("https://www.audi.de/de/brand/de/neuwagen.html")
# choose A3 model
chrome_driver.find_element_by_xpath('//*[#id="list"]/div[1]/ul/li[2]/a[2]').click()
# choose sedan version
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '//*[#id="a3limo"]/div/a'))).click()
# start model configuration
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[2]/div/div[6]/div[2]/div/div[1]/ul/li[1]/a'))).click()
# choose the s-line competition package
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[2]/div/div[7]/div[2]/div[2]/div[3]/div[1]/div/div[1]/div/div[1]/span/span'))).click()
# accept the s-line competition package
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[5]/div/div/div/div/div/ul[2]/li[2]/a'))).click()
Now, the code fail already on the line start model configuration (see "Konfiguration starten" button on webpage https://www.audi.de/de/brand/de/neuwagen/a3/a3-limousine-2019.html). The xPath must be correct and the element should also be visible, so what am I doing wrong here?
Actually required link becomes visible only if to scroll page down.
Try to use this piece of code to click link:
configuration_start = chrome_driver.find_element_by_xpath('//a[#title="Konfiguration starten"]')
chrome_driver.execute_script('arguments[0].scrollIntoView();', configuration_start)
configuration_start.click()
As navigation panel has fixed position it might overlap target link, so you can change navigation panel style before handling link:
nav_panel = chrome_driver.find_element_by_xpath('//div[#data-module="main-navigation"]')
driver.execute_script('arguments[0].style.position = "absolute";', nav_panel)
The following seems to work for me. I have added waits for elements and used a simulated click of the element via javascript.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
url = 'https://www.audi.de/de/brand/de/neuwagen.html'
d = webdriver.Chrome()
d.get(url)
WebDriverWait(d,10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '[data-filterval="a3"]'))).click()
d.get(WebDriverWait(d,10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#a3limo .mf-model-details a'))).get_attribute('href'))
element = WebDriverWait(d,10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '[title="Konfiguration starten"]')))
d.execute_script("arguments[0].click();", element)