标签: webdriverwait

Python + Selenium:等到元素完全加载

所以我一直在尝试使用 Selenium 中调用的函数:

wait = WebDriverWait(browser, 20).wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="accountStandalone"]/div/div/div[2]/div/div/div[1]/button')))
wait.click()
Run Code Online (Sandbox Code Playgroud)

在我开始说这个问题之前。我想要做的 Selenium 基本上是制作一个自动写入这张图片中的论坛的 Selenium:

图1

这不是任何并发症。但是,每当我按下“Skapa Konto”时,它都会加载并等待新页面出现,即:

图2

就是上图。我的想法是,我希望它应该等到它给我那个“图片”(这是同一个链接,所以它不会做任何更改)所以我认为更好的做法是等到文本等“FORTSÄTT或 HELLO”是浏览器。然后继续。

但是,我在尝试使用它时遇到了问题。原因是它不会等到找到它,而是立即执行它不应该做的其他事情。现在它只是跳过等待,就像该功能不起作用或根本不存在一样。我做错了什么?


更新:

我所知道的是,每当我尝试在网站上注册时 - 该网站不会改变,这意味着当它成为一个成功的帐户时,它会将我带到一个新页面。但它会自动刷新并说它成功了。所以这意味着我想以某种方式制作一些东西,它检查并查看页面是否发生了新的事情。如果没有,再等等再试一次?...类似的东西?

我会做的是等检查是否有:

<div class="confirmation-title nsg-font-family--platform nsg-text--black edf-title-font-size--xlarge js-confirmationTitle">NU ÄR DU MEDLEM, Hello.</div>
Run Code Online (Sandbox Code Playgroud)

或者

<button type="button" class="nsg-button nsg-bg--black register-next-step-cta js-nextStepCta">FORTSÄTT</button>
Run Code Online (Sandbox Code Playgroud)

然而,问题正如我所说,每当我按下“SKAPA KONTO” - 它只是等待服务器再次检查,然后自动刷新页面并说成功。

python selenium webdriver selenium-webdriver webdriverwait

4
推荐指数
1
解决办法
1万
查看次数

Python中出现错误“其他元素将获得点击”

我试图单击这样的链接:

<div class="loading" style="display:none;">
<p class="btn blue"><span>?????</span></p>
<a href="javascript:void(0);" onclick="get_more();"></a>
</div>
Run Code Online (Sandbox Code Playgroud)

我使用了这段代码:

element = WebDriverWait(driver, 30).until(lambda x: x.find_element_by_css_selector(".btn.blue"))  # @UnusedVariable
element.click()
Run Code Online (Sandbox Code Playgroud)

我收到这样的错误,该怎么解决?

selenium.common.exceptions.WebDriverException: Message: unknown error: Element <p class="btn blue">...</p> is not clickable at point (391, 577). Other element would receive the click: <a href="javascript:void(0);" onclick="get_more();"></a>
(Session info: headless chrome=69.0.3497.100)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)
Run Code Online (Sandbox Code Playgroud)

selenium webdriver python-3.x selenium-webdriver webdriverwait

4
推荐指数
2
解决办法
1808
查看次数

Selenium 开关选项卡

由于 Firefox 不再支持 Control + T 选项卡,我开始使用 driver.execute_script("window.open('URL', 'new_window')")

我试图显示我打开的不同选项卡的标题并在它们之间切换。对于下面的示例,我希望输出为 facebook、google 并返回到 facebook。现在输出是 facebook、facebook 和 facebook。

我从这里尝试了答案,但它也不起作用:使用 selenium webdriver 切换回父选项卡

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.facebook.com/")
print(driver.title)

driver.execute_script("window.open('http://google.com', 'new_window')")
print(driver.title)

driver.switch_to.window(driver.window_handles[0])
print(driver.title)
Run Code Online (Sandbox Code Playgroud)

更新:我尝试了以下代码,但仍然无法正常工作。

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("http://www.facebook.com/")
print(driver.title)
window_before = driver.window_handles[0]

driver.execute_script("window.open('http://google.com', 'new_window')")
window_after = driver.window_handles[1]
driver.switch_to.window(window_after)
print(driver.title)
Run Code Online (Sandbox Code Playgroud)

python selenium tabs window-handles webdriverwait

4
推荐指数
1
解决办法
4996
查看次数

如何移至 Python Selenium 的下一页?

我正在尝试为特定站点构建代理抓取工具,但无法转到下一页。

这是我正在使用的代码。

如果您回答了我的问题,请向我解释一下您使用的内容,如果可以,请向我解释有关此类代码的任何好的教程,请提供一些:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

options = Options()
#options.headless = True     #for headless
#options.add_argument('--disable-gpu') #for headless and os win

driver = webdriver.Chrome(options=options)

driver.get("https://hidemyna.me/en/proxy-list/")
time.sleep(10) #bypass cloudflare


tbody = driver.find_element_by_tag_name("tbody")
cell = tbody.find_elements_by_tag_name("tr")

for column in cell:
    column = column.text.split(" ")
    print (column[0]+":"+ column[1]) #ip and port

nxt = driver.find_element_by_class_name('arrow_right')
nxt.click()
Run Code Online (Sandbox Code Playgroud)

python selenium screen-scraping python-3.x webdriverwait

4
推荐指数
1
解决办法
1万
查看次数

org.openqa.selenium.ElementClickInterceptedException:在无头模式下使用 Selenium 和 Java 截获元素点击错误

我有一个项目,我正在使用 java 和 selenium。在 UI 模式下测试工作正常。但是在无头模式下我收到此错误

org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562). Other element would receive the click: <div _ngcontent-yrc-c26="" class="footer">...</div>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题(在 UI 模式下工作)。这是我的代码

WebDriver driver = getWebDriver();
        WebElement element;
        Thread.sleep(60000);
        element = driver.findElement(By.xpath("//label[@formcontrolname='reportingDealPermission']"));
        element.click();
Run Code Online (Sandbox Code Playgroud)

为什么在 selenium 中没有移动到元素并打破所有层的操作。这是用户界面。这是在 UI 模式下工作,而不是在无头模式下工作,睡眠了 6 分钟但没有解决,所以这不是时间问题

在此处输入图片说明

java selenium xpath css-selectors webdriverwait

4
推荐指数
3
解决办法
1万
查看次数

如何在发送密钥 selenium c# 之前清除文本字段

我正在编写一个简单的 selenium 测试,它发送一个不正确的字母字符串,然后提交并返回和错误。然后我想发送一串字母,但这次使用正确的字符串,所以它被接受了。

我在测试中面临的问题是第一组字符串已经在文本字段中,所以当我去提交第二组时,它将它添加到已经提交的第一个字符串中。

所以我本质上需要做的是发送第一个字母字符串然后需要清除文本字段然后发送第二个字母字符串。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using System.Threading;

namespace Exercise1
{
    class RunPath
    {

            static void Main()
            {

                IWebDriver webDriver = new ChromeDriver();
                webDriver.Navigate().GoToUrl("https://energy.gocompare.com/gas-electricity");
                webDriver.Manage().Window.Maximize();


            String title = webDriver.Title;

            String expectedTitle = "Utilities from Go Compare";
            if (title.Contains(expectedTitle))
            {
                Console.WriteLine("Tile is matching with expected value");
            }
            else
            {
                Console.WriteLine("Tile is matching with expected value");
            }

            webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();

            webDriver.FindElement(By.XPath(".//input[@type = 'text']")).SendKeys("W30PN#");

            webDriver.FindElement(By.XPath(".//button[@type = …
Run Code Online (Sandbox Code Playgroud)

c# selenium selenium-webdriver webdriverwait

3
推荐指数
1
解决办法
1万
查看次数

DeprecationWarning:在Python中使用Geckodriver和Selenium将setter用于无头属性,而不是set_headless opts.set_headless(headless = True)

我有一个非常基本的Python脚本,该脚本可以在本地计算机(Mint 19)上完美运行,但是在远程机器上(Ubuntu 16.04)却无法运行。相同的文件,两个Python 3.7。我在/ usr / local / bin中有geckodriver,它从命令行使用gecko --version从路径中检出。我不知道是什么问题。geckodriver.log文件只是说:

1541268536111   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.Mt6zAyZc7D01"
*** You are running in headless mode.
1541268546125   Marionette  INFO    Listening on port 33632
Run Code Online (Sandbox Code Playgroud)

来自终端的错误是:

root@dev1:/home/krypterro/PycharmProjects/corbot# python3 test1.py
 2018-11-03 12:28:22,442 -  INFO -  Application - Start
test1.py:12: DeprecationWarning: use setter for headless property instead of set_headless
  opts.set_headless(headless=True)
Traceback (most recent call last):
  File "test1.py", line 21, in <module>
    main()
  File "test1.py", line 14, in main
    driver = webdriver.Firefox(options=opts) …
Run Code Online (Sandbox Code Playgroud)

firefox selenium python-3.x geckodriver webdriverwait

3
推荐指数
1
解决办法
3851
查看次数

使用动态鼠标悬停事件抓取网站

我正在尝试抓取从鼠标悬停事件动态生成的数据。
我想从https://slushpool.com/stats/?c=btc的哈希率分布图表中捕获信息,该图表是在滚动每个圆圈时生成的。

下面的代码从网站获取 html 数据,并返回鼠标经过一个圆圈时填充的表格。但是,我无法弄清楚如何触发每个圆圈的鼠标悬停事件以填充表格。

from lxml import etree
from xml.etree import ElementTree
from selenium import webdriver

driver_path = "#Firefox web driver"
browser = webdriver.Firefox(executable_path=driver_path)
browser.get("https://slushpool.com/stats/?c=btc") 


page = browser.page_source #Get page html 
tree = etree.HTML(page) #create etree

table_Xpath = '/html/body/div[1]/div/div/div/div/div[5]/div[1]/div/div/div[2]/div[2]/div[2]/div/table'

table =tree.xpath(table_Xpath) #get table using Xpath

print(ElementTree.tostring(table[0])) #Returns empty table. 
#Should return data from each mouseover event
Run Code Online (Sandbox Code Playgroud)

有没有办法触发每个圆圈的鼠标悬停事件,然后提取生成的数据。

预先感谢您的帮助!

python selenium svg web-scraping webdriverwait

3
推荐指数
1
解决办法
3850
查看次数

无效的元素状态:元素必须是用户可编辑的,以清除尝试使用 Selenium 在下拉菜单上单击并插入日期的错误

我正在尝试单击此日历并使用 selenium 自动插入日期,但出现以下错误:

无效元素状态:元素必须是用户可编辑的才能清除它。

HTML 片段

<a id="enddate-dropdown" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="">
                <p class="custom-datepickers__date-prefix ng-binding">To:</p>
                <!-- ngIf: displayEndDate -->
                <!-- ngIf: !displayEndDate --><div ng-if="!displayEndDate" class="custom-datepickers__no-date ng-scope"></div><!-- end ngIf: !displayEndDate -->
</a>
Run Code Online (Sandbox Code Playgroud)

代码片段

myclass.SetDateByXpath("//*[@id=\"enddate-dropdown\"]/p", myclass.GetDate("yyyy/MM/dd", mydate));

public void SetDateByXpath(String element, String value)
    {
        WebElement webElement = ExplicitWaitOnElement(By.xpath(element));       
        ((JavascriptExecutor) driver).executeScript(
                "arguments[0].removeAttribute('readonly','readonly')",webElement);
        webElement.clear();
        webElement.sendKeys(value);
    }
Run Code Online (Sandbox Code Playgroud)

如果我手动设置日期,这是 HTML:

<a id="enddate-dropdown" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="">
                <p class="custom-datepickers__date-prefix ng-binding">To:</p>
                <!-- ngIf: displayEndDate --><p ng-if="displayEndDate" class="ng-binding ng-scope">2019/11/21</p><!-- end ngIf: displayEndDate -->
                <!-- ngIf: !displayEndDate -->
</a>
Run Code Online (Sandbox Code Playgroud)

可能网站已更改,但现在我不知道如何设置此值。任何帮助将不胜感激。 …

selenium selenium-webdriver angular webdriverwait expected-condition

3
推荐指数
1
解决办法
633
查看次数

WebDriverWait 在 Selenium 4 中被弃用

我得到一个

警告:(143,13) 'WebDriverWait(org.openqa.selenium.WebDriver, long)' 已弃用

在硒 4.0.0-alpha-3 中。

但官方Selenium 页面仅列出

WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds, long sleepTimeOut)
Run Code Online (Sandbox Code Playgroud)

已弃用。

怎么了?我正在使用 IntelliJ,这可能是他们的问题吗?

java selenium selenium-webdriver webdriverwait selenium4

3
推荐指数
4
解决办法
1万
查看次数