lager | oriented design using the unidirectional data | State Container library
kandi X-RAY | lager Summary
Support
Quality
Security
License
Reuse
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
lager Key Features
lager Examples and Code Snippets
Trending Discussions on lager
Trending Discussions on lager
QUESTION
I'm tring to do a autocomplete from json url, it works good.
Now what I want, it's when I click to the autocomplete, I want to display the import button and if input is empty or we put a new value (not in the import), display the create button.
Give you a example on what i'm doing with some datas:
$('#search-deal').autocomplete({
source: function(request, response) {
var data =[{
"id": 1671,
"title": "Queens Park Tyres deal"
}, {
"id": 1672,
"title": "Wildman Craft Lager deal"
}, {
"id": 1673,
"title": "General Store deal"
}, {
"id": 1674,
"title": "Deluxe Off Licence deal"
}, {
"id": 1675,
"title": "Ahmed Halal Bazaar deal"
}];
var datamap = data.map(function(i) {
return {
label: i.id + ' - ' + i.title,
value: i.id + ' - ' + i.title,
desc: i.title
}
});
var key = request.term;
datamap = datamap.filter(function(i) {
if(i.label.toLowerCase().indexOf(key.toLowerCase()) >= 0){
document.getElementById("create").style.visibility = 'hidden';
document.getElementById("import").style.visibility = 'visible';
return i.label.toLowerCase().indexOf(key.toLowerCase()) >= 0;
};
});
response(datamap);
},
minLength: 1,
delay: 100
});
Créer une affaire
Importer
The problem here, it's when I write "p", the button import show up and I want to show up only when I click to the autocomplete. The second problem, it's the button create nevere come back if value is empty or put another value
Anybody can help me ?
ANSWER
Answered 2022-Apr-12 at 10:31I understand from the shared snippet that you are using jquery ui autocomplete
. I would suggest following changes/updates to your code
- For changing button display on selecting the autocomplete item, use
select
event. https://api.jqueryui.com/autocomplete/#event-select - Whenever user types something, hide the import button. Display it only when an item is selected.
- For handling empty input case, use
oninput
event.
I have made following changes to the code you shared
- Added a new function to handle button toggle
- Hide the import button from
source
property i.e. when user type some input and also when input box is blank - Show the import button when user selects an autocomplete option
Working code link: https://plnkr.co/edit/PgzUuOADhIqk9zbl?preview
I hope this solves your issue
QUESTION
I cant figure out what i´m doing wrong. I keeps returning "På lager" in the if statement. But Shop 3, should return "Ikke på lager" in the foreach loop, where it calls the function.
array (
"price" => 5,
"extUrl" => "https://tv2.dk/",
"logo" => "",
"stock" => "in stock",
"ean" => "5707400342642",
"shopName" => "Shop2",
),
"Shop2" => array (
"price" => 99,
"extUrl" => "https://cnn.com/",
"logo" => "https://eb.dk/",
"stock" => "in stock",
"ean" => "51010101010",
"shopName" => "Shop2.dk",
),
"Shop3" => array (
"price" => 50000000,
"extUrl" => "https://v2.dk/",
"logo" => "https://eb.dk/",
"stock" => "out of stock",
"ean" => "5707406556565655",
"shopName" => "Shop3",
)
);
foreach($shopsArray as $abc){
echo CheckStock();
}
function checkStock(){
global $shopsArray;
foreach ($shopsArray as $stockMgmt) {
if ($stockMgmt["stock"] == "in stock"){
return "På lager";
} else {
return "Ikke på lager";
}
}
}
ANSWER
Answered 2022-Mar-16 at 21:18You return
from your checkStock()
function as soon as $stockMgmt["stock"] == "in stock"
, and you do that three times. Try this code instead:
[
"price" => 5,
"stock" => "in stock",
"ean" => "5707400342642",
"shopName" => "Shop2",
],
"Shop2" => [
"price" => 99,
"stock" => "in stock",
"ean" => "51010101010",
"shopName" => "Shop2.dk",
],
"Shop3" => [
"price" => 50000000,
"stock" => "out of stock",
"ean" => "5707406556565655",
"shopName" => "Shop3",
]
];
function checkStock($stockManagement)
{
return ($stockManagement["stock"] == "in stock") ? "På lager" : "Ikke på lager";
}
foreach ($shops as $shop => $stockManagement) {
echo $shop . ' = ' . CheckStock($stockManagement) . '
';
}
The function now uses the stock management array as an argument. In the function I use the Ternary Operator.
We only use one loop to walk through the main array of shops.
Note how I don't abbreviate unnecessarily. Variable names should clarify the meaning of the value, but not the type. So, not $shopsArray
but just $shops
or $shopsStock
.
Now tested, thanks to medilies: PHP fiddle
QUESTION
I'm having an issue with a svg file that renders differently on different OS. It even looks different in different editors. (Never mind the size difference below)
MacOS Safari:
Windows FileExplorer:
Linux Chrome:
I didn't create it myself. It was created on a Windows computer, in Inkscape it seems.
I wonder why it looks different? Is it possible to make it look the same, or does it need be recreated?
Here is the svg:
B
ANSWER
Answered 2022-Mar-10 at 18:34Your screenshots indicate, that your font (Wide Latin) is installed locally on your windows desktop but not available on other systems.
You might embed the font in your svg file using a converting tool like transfonter:
B
In the above example I only embedded the character B (reducing the filesize).
Embedded fonts and previewsMost image preview tools and graphic applications just can't parse webfonts like woff, woff2.
... Quite likely, they can't parse any embedded font format at all.
You might try .ttf truetype since it should be the format providing best legacy compatibility.
If you need the most robust/consistent rendering in any application you might convert your svg text to elements.
- install the font locally
- open the svg in an editor (like Ai, inkscape etc)
- convert the text element to a path (inscape howTo)
I strongly recommend this approach especially for logo svgs.
QUESTION
Consider the following code:
#include
using namespace std;
int main(int argc, char *argv[])
{
long double test = 0xFFFFFFFFFFFFFFFF;
cout << "1: " << test << endl;
unsigned long long test2 = test;
cout << "2: " << test2 << endl;
cout << "3: " << (unsigned long long)test << endl;
return 0;
}
Compiling this code with GCC g++ (7.5.0) and running produces the following output as expected:
1: 1.84467e+19
2: 18446744073709551615
3: 18446744073709551615
However compiling this with the Microsoft Visual C++ compiler (16.8.31019.35, both 64-bit and 32-bit) and running produces the following output:
1: 1.84467e+19
2: 9223372036854775808
3: 9223372036854775808
When casting a value to an unsigned long long
, the MSVC compiler won't give a value lager than the max of a (signed) long long
.
Am I doing something wrong?
Am I running into a compiler limitation that I do not know about?
Does anyone know of a possible workaround to this problem?
ANSWER
Answered 2022-Mar-04 at 12:09Because a MSVC long double
is really just a double
(as pointed out by @drescherjm in the comments), it does not have enough precision to contain the exact value of 0xFFFFFFFFFFFFFFFF. When this value is stored in the long double
it gets "rounded" to a value that is lager than 0xFFFFFFFFFFFFFFFF. This then causes undefined behaviour when converting to an unsigned long long
.
QUESTION
I'm trying to opening a browser in my own chrome. I'm using Selenium WebDriver right know but I want to use my own chrome browser.
My code:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')
driver.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
buyButton = False
while buyButton is False:
try:
addToCartBtn = addButton = driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')
print("Varen er udsolgt")
time.sleep(1)
driver.refresh()
except:
addToCartBtn = addButton = driver.find_element_by_xpath('//*[@id="picker-trigger"]')
print("Varen er på Lager")
buyButton = True
while buyButton is True:
time.sleep(1)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Vælg størrelse']"))).click()
driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Læg i indkøbskurv']"))).click()
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Indkøbskurv"]'))).click()
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".z-coast-base__totals-tile .z-1-button__content"))).click()
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Registrér dig"]'))).click()
What I have tried:
driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')
The Error:
selenium.common.exceptions.WebDriverException: Message: 'driver' executable needs to be in PATH.
I have tried to follow this answer, but I can not make it work.
ANSWER
Answered 2022-Jan-17 at 16:50try this:
import webbrowser
url = 'http://docs.python.org/'
# MacOS
chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
# Windows
# chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
# Linux
# chrome_path = '/usr/bin/google-chrome %s'
webbrowser.get(chrome_path).open(url)
QUESTION
I'm creating a script for adding multiple users in Active Directory. I stumbled upon this link, when I couldn't get the guide described in the question to work either. I then tried one of the solutions in the comments
Import-Module ActiveDirectory
# this defaults to csv fields delimited by a comma. If your CSV file uses a different
# character, then add parameter '-Delimiter' followed by the actual character
$ADUsers = Import-Csv -Path 'C:\Users\Desktop\Powershell files\EM-mis-new-AD.csv'
# the Where-Object clause is just a precaution to omit records that have no username value
$ADUsers | Where-Object { $_.username -match '\S'} | ForEach-Object {
$Username = $_.username
if (Get-ADUser -Filter "SamAccountName -eq '$Username'" -ErrorAction SilentlyContinue) {
Write-Warning "A user account with SamAccountName '$Username' already exist in Active Directory."
}
else {
$Firstname = $_.firstname
$Lastname = $_.lastname
# use splatting on cmdlets that use a lot of parameters
$userParams = @{
SamAccountName = $Username
UserPrincipalName = "$Username@Mydomain.com"
Name = "$Firstname $Lastname"
GivenName = $Firstname
Surname = $Lastname
Enabled = $true
DisplayName = "$Firstname, $Lastname"
Path = $_.ou
AccountPassword = (ConvertTo-SecureString $_.Password -AsPlainText -Force)
ChangePasswordAtLogon = $true
}
# create the user and report back
New-ADUser @userParams
Write-Host "Created new user '$Username' with initial password: $($_.Password)"
}
}
Here is my CSV file
firstname;lastname;username;password;ou
Mette;Frederiksen;MeFr;Password1;OU=Salg,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
Sussi;Hart;SuHa;Password1;OU=Salg,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
Ove;Tylstrup;OvTy;Password1;OU=Salg,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
Karlos;Mondolez;KaMo;Password1;OU=Lager,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
Anne;Otto;AnOt;Password1;OU=Lager,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
Dennis;Ågard;DeÅg;Password1;OU=Lager,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
Helena;Riss;HeRi;Password1;OU=Okonomi,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
Risa;Lamende;RiLa;Password1;OU=Okonomi,OU=Users,OU=RGD Aarhus,DC=rgd,DC=local
However, when I run the above code nothing happens
PS C:\Users\RGDAdmin> C:\Users\RGDAdmin\Documents\ADUser.ps1
PS C:\Users\RGDAdmin>
When I add the Delimiter
parameter, I get this
Created new user 'KaMo' with initial password: Password1
New-ADUser : The directory service was unable to allocate a relative identifier
At C:\Users\RGDAdmin\Documents\ADUser.ps1:31 char:9
+ New-ADUser @userParams
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Anne Otto,OU...DC=rgd,DC=local:String) [New-ADUser], ADException
+ FullyQualifiedErrorId :
ActiveDirectoryServer:8208,Microsoft.ActiveDirectory.Management.Commands.NewADUser
PS. I know the password is bad practice in terms of passwords
ANSWER
Answered 2022-Jan-04 at 22:09Your file is delimited by semicolons, so you will definitely need to specify the -Delimiter
parameter. But the documentation has a caveat:
To specify a semicolon (;) enclose it in single quotation marks.
So it should look like this:
$ADUsers = Import-Csv -Delimiter ';' -Path 'C:\Users\Desktop\Powershell files\EM-mis-new-AD.csv'
If that still results in that RID error, then there's possibly something wrong on the server. Can you create users manually using AD Users and Computers?
QUESTION
I'm trying to make a bot that can press a button for me with parent class name.
My code:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
browser = webdriver.Chrome('C:/Users/rober/OneDrive/Skrivebord/bot/chromedriver')
# Graffik kort
browser.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
buyButton = False
while buyButton is False:
try:
addToCartBtn = addButton = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')
print("Varen er udsolgt")
time.sleep(1)
browser.refresh()
except:
addToCartBtn = addButton = browser.find_element_by_xpath('//*[@id="picker-trigger"]')
print("Varen er på Lager")
buyButton = True
while buyButton is True:
time.sleep(1)
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click()
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Vælg størrelse']"))).click()
browser.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))))
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Læg i indkøbskurv']"))).click()
WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Indkøbskurv"]'))).click()
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'z-1-button z-coast-base-primary-accessible z-coast-base__totals-tile__button-checkout z-1-button--primary z-1-button--button'))).click()
What I have tried:
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'z-1-button z-coast-base-primary-accessible z-coast-base__totals-tile__button-checkout z-1-button--primary z-1-button--button'))).click()
The Error:
selenium.common.exceptions.TimeoutException: Message:
ANSWER
Answered 2022-Jan-10 at 17:32I am assuming that you are trying to click on this button:
If yes, then you may use the below code to click it:
WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, "//*[@class='z-coast-base__totals-tile']//*[@class='z-1-button__content']"))).click()
If you essentially want a CSS SELECTOR instead of an xpath, you may replace it with this:
WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div[class='z-coast-base__totals-tile'] div[class='z-1-button__content']"))).click()
OR even this:
WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".z-coast-base__totals-tile .z-1-button__content"))).click()
Also, I see the Webelement locator you are using for addToCartBtn
is poor. It is absolute and very unreliable. Try to make them as relative as possible. I am referring to this one: /html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button
QUESTION
I tried to put data in to a table using variabels, as you can see down below in the code. When I'm running this piece of code I get the following error:
What I want the code to do is, get the data out of the parameters i'm giving in to the function insert_data. And then using the wildcard questionmark symbol. To get the option to use the variabels as data. Not quite sure if it's the most propper way of doing so. But it does work in other occations. I just don't get why it does not work in this piece of code.
Traceback (most recent call last):
File "{path}", line 65, in
insert_data()
File "{path}", line 56, in insert_data
query ("INSERT INTO computers (name, os, mac_addr) VALUES "
File "{path}", line 8, in query
cursor.execute(query, args)
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
MY CODE
import cgi
import sqlite3
from os import path, environ
def query(query, *args):
db = sqlite3.connect(database)
cursor = db.cursor()
cursor.execute(query, args)
resultaat = cursor.fetchall()
db.commit()
db.close()
return resultaat
def database_create():
if path.isfile(database) != True:
query("CREATE TABLE 'computers' ('name' TEXT, 'os' TEXT, 'mac_addr' TEXT,"
"'create_date' timestamp DEFAULT current_timestamp)")
query("CREATE TABLE 'data' ('computer_id' integer, 'mem_usage' float,"
"'cpu_usage' float, 'total_size' float, 'used_size' float, 'free_size' float,"
"'create_date' timestamp DEFAULT current_timestamp)")
query("CREATE TABLE 'grafieken' ('name' TEXT, 'legend' TEXT)")
query("CREATE TABLE 'gebruikers'('u_name' TEXT, 'p_word' TEXT)")
query("INSERT INTO 'gebruikers' (u_name, p_word) VALUES ('beheerder',"
"'695badbd075fdacd8638a600712f9aec74dd85b6ae61f7ab7f0f45e438196bf0aac117102d328e3d4e92fd5fc78f593a50875f900a7fe59f5d463bbf35af245c3b605ec3b6f91cbec7452801ca5ca95ebf00b248e73d07b9934d25ab21b6943a83d1944450854ef05044be01ff0d3b72b158209a70a28c3e063ec6a7f806d610')")
query("INSERT INTO grafieken VALUES ('Totale hardeschijf ruimte', 'Ruimte (GB), hoger is beter')")
query("INSERT INTO grafieken VALUES ('Beschikbare hardeschijf ruimte', 'Ruimte (GB), hoger is beter')")
query("INSERT INTO grafieken VALUES ('Gebruikte hardeschijf ruimte', 'Ruimte (GB), lager is beter')")
query("INSERT INTO grafieken VALUES ('Geheugenverbruik', 'Geheugen (%), lager is beter')")
query("INSERT INTO grafieken VALUES ('CPU-verbruik', 'Processor (%), lager is beter')")
print ('done')
elif path.isfile(database) == True:
print ('DB already exists')
else:
print('failed')
def insert_data():
try:
import psutil
except ImportError:
print('no psutil installed')
exit(1)
import platform
import uuid
diskspace = psutil.disk_usage('/')
spacetoGB = [diskspace[0] // (2 ** 30), diskspace[1] // (2 ** 30), diskspace[2] // (2 ** 30)] # Total, used, free
name = platform.uname()[1],
mac_addr = '%012x' % uuid.getnode(), # https://stackoverflow.com/questions/13864608/get-mac-address-in-python-and-append-to-string
#totalsize = spacetoGB[0],
#usedsize = spacetoGB[1],
#freesize = spacetoGB[2],
os = platform.system() + " " + platform.release(),
# memusage = psutil.virtual_memory().percent,
# cpu_usage = psutil.cpu_percent(interval=1)
query ("INSERT INTO computers (name, os, mac_addr) VALUES "
"(?,?,?)", *(name, os, mac_addr,))
data = 'Record added'
print (data)
#return data
database = "tester.db"
database_create()
insert_data()
ANSWER
Answered 2022-Jan-04 at 17:43The commas (,
) terminating the set statments (eg name = platform.uname()[1],
) cast the variables as tuples.
QUESTION
Context: Link
—————————————————————
I want to press that little back in the top right corner. I have copyed the selector from the little bag. And now I want it to press on it in my script.
The selector code look likes this:
#z-navicat-header-root > header > div:nth-child(3) > div > div > div > div.mrHm0Z.C3wGFf > div > div > div > div.z-navicat-header_topRow > div.z-navicat-header_langNavTools > div > div.z-navicat-header_navToolItem.z-navicat-header_navToolItem-bag > a > div > svg
What i haved tried:
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.z-navicat#z-navicat-header-root > header > div:nth-child(3) > div > div > div > div.mrHm0Z.C3wGFf > div > div > div > div.z-navicat-header_topRow > div.z-navicat-header_langNavTools > div > div.z-navicat-header_navToolItem.z-navicat-header_navToolItem-bag > a > div > svg"))).click()
The Code:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
browser = webdriver.Chrome('C:/Users/rober/OneDrive/Skrivebord/bot/chromedriver')
# Graffik kort
browser.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
buyButton = False
while buyButton is False:
try:
addToCartBtn = addButton = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')
print("Varen er udsolgt")
time.sleep(1)
browser.refresh()
except:
addToCartBtn = addButton = browser.find_element_by_xpath('//*[@id="picker-trigger"]')
print("Varen er på Lager")
buyButton = True
while buyButton is True:
time.sleep(3)
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click()
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Vælg størrelse']"))).click()
browser.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))))
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Læg i indkøbskurv']"))).click()
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.z-navicat#z-navicat-header-root > header > div:nth-child(3) > div > div > div > div.mrHm0Z.C3wGFf > div > div > div > div.z-navicat-header_topRow > div.z-navicat-header_langNavTools > div > div.z-navicat-header_navToolItem.z-navicat-header_navToolItem-bag > a > div > svg"))).click()
Right now it doesn’t work, but If there are any wise people around selenium and chromedriver out there then you are very welcome to leave a comment on how I fix this problem
Website: Link
ANSWER
Answered 2022-Jan-02 at 11:18There is no need to use the absolute path just call the element, in same way you did with the "accept-banner" by its title attribute:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Indkøbskurv"]'))).click()
or its href attribute:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[href="/cart/"]'))).click()
or by its parent class name:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, '.z-navicat-header_navToolItem-bag a'))).click()
QUESTION
My Code:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
browser = webdriver.Chrome('C:/Users/rober/OneDrive/Skrivebord/bot/chromedriver')
# Graffik kort
browser.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
buyButton = False
while buyButton is False:
try:
addToCartBtn = addButton = browser.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')
print("Varen er udsolgt")
time.sleep(1)
browser.refresh()
except:
addToCartBtn = addButton = browser.find_element_by_xpath('//*[@id="picker-trigger"]')
print("Varen er på Lager")
buyButton = True
while buyButton is True:
time.sleep(3)
accept = browser.find_element_by_id('uc-btn-accept-banner')
browser.execute_script("arguments[0].click();", accept)
element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="picker-trigger"]')))
element.click();
My Error:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="uc-btn-accept-banner"]"}
My problem is that i want to get the size 51.5 in eu sizes but i don't know the code to select that size with the CLASS of the size.
If some one know a solution, just make a comment because i really need some help to find the right solution.
ANSWER
Answered 2022-Jan-01 at 16:09To select the size as 51.5 you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategies:
Code Block:
driver.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Vælg størrelse']"))).click()
driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lager
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page