私信  •  关注

arundeep chohan

arundeep chohan 最近创建的主题
arundeep chohan 最近回复了
4 年前
回复了 arundeep chohan 创建的主题 » 在Python/Selenium中是否启用函数
while True:
    try:
        addButton=WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.XPATH,"(//button[contains(@class,'addToCart')])[1]")))
        addButton.click()
        break
    except:
        browser.refresh()

这里有一个无限循环,等待元素被点击10秒,否则刷新页面。还有其他4个同名的类。

进口

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
libra_content = [[x.find_element(By.XPATH,'./h2[1]').text,x.find_element(By.XPATH,'./p[1]').text] for x in driver.find_elements(By.CLASS_NAME, 'horoscope-content')]

如果想同时存储这两个值,可以对这两个值执行类似的操作。

3 年前
回复了 arundeep chohan 创建的主题 » 如何使用Selenium Python单击#shadow root(closed)内的按钮
host = driver.find_element(By.CSS_SELECTOR,".button-holder.help-button-holder"))
shadowRoot = driver.execute_script("return arguments[0].shadowRoot", host)
shadowRoot.find_element(By.ID,"solver-button")).click()

抓取shadowroot元素,然后找到“解算器”按钮。

4 年前
回复了 arundeep chohan 创建的主题 » 如何在python selenium中获取每个窗口句柄项的标题
for handle in driver.window_handles:
    driver.switch_to_window(handle)
    print(driver.title)

切换到句柄并打印其标题。据我所知,没有别的办法

3 年前
回复了 arundeep chohan 创建的主题 » Django表单向导表单保存
class UserWizard(SessionWizardView):
    template_name = "registration/signup.html"
    form_list = [SignUpForm]
    def done(self, form_list, **kwargs):
        #process_data(form_list)
        form_list[0].save()
        userCreate = form_list[0]
        username = userCreate.cleaned_data.get('username')
        raw_password = userCreate.cleaned_data.get('password1')
        user = authenticate(username=username, password=raw_password)
        if user:
            auth_login(self.request, user)
        return redirect('home')

只需通过保存表单创建一个用户,然后使用auth_登录即可。

4 年前
回复了 arundeep chohan 创建的主题 » python-使用相关下拉列表删除表

一个简单的循环来获取所有SelectDisr选项。你只需要选择每种类型的所有选项。

selectDistr = Select(driver.find_element_by_id("cdgoDist"))

for option in selectDistr.options:
    selectDistr.select_by_value(option.get_attribute('value'))
6 年前
回复了 arundeep chohan 创建的主题 » unfrlatting list在python中返回意外错误
l1 = [[1,2],[3,4]]
l2 = [5, 7]
for i in range(len(l2)):
l1[i].append(l2[i]);

print(l1)

[1,2,5],[3,4,7]]

Extend is for objects.
Append is what you need here.