小编Guy*_*Guy的帖子

在应用之间切换

我有一个场景,我需要使用Selenium和Appium切换应用程序.我从浏览器开始,然后我需要从通知栏中获取一些信息,然后切换回浏览器.我设法将每个过程作为一个独立的过程.但现在我正在努力做到端到端的过程.

我已经开始创建一个webdriver会话,但是当他第一个仍在运行时我无法打开一个新会话.问题是浏览器和appium有不同的会话.一个被称为

_driver = new AndroidDriver<AppiumWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
Run Code Online (Sandbox Code Playgroud)

而第二个是

_webdriver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
Run Code Online (Sandbox Code Playgroud)

selenium android appium

5
推荐指数
1
解决办法
401
查看次数

如何使用Selenium Webdriver获取当前窗口大小?

我在屏幕分辨率(1366 X 768)上运行,但是当我调用"getSize().getWidth()"和"getSize().getHeight()"方法时,得到的结果是:宽度的大小是:1382高度大小为:IE,FF和Chrome网页为744.使用的网址:https://www.google.com

java selenium selenium-webdriver

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

限制 Selenium FindElement() 的超时时间

如何限制/减少超时时间FindElement?我正在抓取一个网站。对于出现在数千页中的表格,我可以使用说明没有信息的元素或表格。我搜索这些元素之一,当丢失时,我会搜索另一个。问题是当其中一个不存在时,需要很长时间才能FindElement超时。这个期限可以缩短吗?可以为每个元素定义超时期限吗?我发现关于等待的所有内容都是延长超时时间...如果有帮助的话,我正在 .NET 环境中工作。

c# selenium timeout selenium-webdriver

5
推荐指数
1
解决办法
4158
查看次数

无法从zillow网站上删除一些元素

我正试图抓住zillow网站的内容.

例如:https: //www.zillow.com/homedetails/689-Luis-Munoz-Marin-Blvd-APT-508-Jersey-City-NJ-07310/108625724_zpid/

问题是我无法抓住价格和税收历史的内容.我认为它们是javascript元素加载页面加载时因此尝试使用selenium但我仍然无法得到它们.以下就是我的尝试.

phistory = soup.find("div",{"id": "hdp-price-history"})
print phistory
Run Code Online (Sandbox Code Playgroud)

HTML

<div class="loading yui3-widget yui3-async-block yui3-complaintstable yui3-hdppricehistory yui3-hdppricehistory-content" id="hdp-price-history">
  div class="zsg-content-section zsg-loading-spinner_lg"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是最外面的元素,但里面没有任何元素.也尝试过没有产生任何元素soup.find_all("table",class_ = "zsg-table yui3-toggle-content-minimized").

html python selenium screen-scraping beautifulsoup

5
推荐指数
1
解决办法
484
查看次数

在Selenium / Python中的div中循环遍历div

我有这个HTML:

<div class="container">
    <div class="name">James</div>
    <div>Rodriguez</div>
    <div class="image">
        <div><img src="https://example.com/1.jpg"></div>
    </div>
</div>
<div class="container">
    <div class="name">Harry</div>
    <div>Kane</div>
    <div class="image">
        <div><img src="https://example.com/2.jpg"></div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

如何遍历所有容器并获取名称,姓氏(第二个div)和图像URL(img src)?到目前为止,我想到了这个:

items = []

containers = driver.find_elements_by_xpath('//div[@class="container"]')

for items in containers:
    name = items.find_element_by_xpath('//div[@class="name"]')
    print(name.text)
Run Code Online (Sandbox Code Playgroud)

这应该给出两个名称。但是,我得到的'James'是输出的两倍,而没有'Harry'。

谢谢!

python selenium xpath loops selenium-webdriver

5
推荐指数
2
解决办法
2423
查看次数

收到错误“DesiredCapability 类型的方法 chrome() 未定义”

上下文:从以下代码中收到错误,因为方法 chrome 未定义:

package zapSeleniumIntegration;

import java.lang.reflect.Proxy;    
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class BrowserDriverFactory {

    static WebDriver driver;
    public static WebDriver createChromeDriver(Proxy proxy, String path) {
    // Set proxy in the chrome browser
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();//Getting error as method chrome undefined
            capabilities.setCapability("127.0.0.1", 8080);
            // Set system property for chrome driver with the path
            System.setProperty("webdriver.chrome.driver", "C:\\Users\\kotla.naveen\\Desktop\\chromedriver.exe");
            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            ChromeOptions options = new ChromeOptions();
            options.merge(capabilities);
            return new ChromeDriver(options); 
    }
}
Run Code Online (Sandbox Code Playgroud)

java selenium selenium-chromedriver desiredcapabilities

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

我得到:chart_studio.exceptions.PlotlyRequestError:未提供身份验证凭据

我在本地工作(在我的电脑上)只是测试和学习 PLOTLY 3.7.5。anaconda env 处于活动状态。代码示例由 plotly 给出

代码:

import plotly.plotly as py  # Here all begins (Look)
# import chart_studio.plotly as py  # inted of the line bellow (optional to  try)
import plotly.graph_objs as go
import pandas as pd
from datetime import datetime

if __name__ == '__main__':
    df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
    trace = go.Ohlc(x=df['Date'],
                    open=df['AAPL.Open'],
                    high=df['AAPL.High'],
                    low=df['AAPL.Low'],
                    close=df['AAPL.Close'])
    data = [trace]
    py.iplot(data, filename='simple_ohlc')
Run Code Online (Sandbox Code Playgroud)

注意(看):我收到警告错误:

'请安装 chart-studio 包并改用 chart_studio.plotly 模块。

python plotly ohlc

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

pytest:如果设置出现问题,如何跳过测试用例并直接跳转到清理?

我知道在 pytest 中,设置和清理的首选方法是使用yield,例如

class TestSomething():
    @pytest.fixture(scope="class", autouse=True)
    def setup_cleanup(self, request):
        ...
        yield
        ...

    def test_something(self):
        ...
Run Code Online (Sandbox Code Playgroud)

问题是,如果设置部分出现故障,在yield发生之前,清理代码将没有机会运行。

是否有可能,当设置中发生某些严重故障时,所有测试用例都被跳过,并且控制权由清理接管(yield在方法之后setup_cleanup)?

python pytest

5
推荐指数
1
解决办法
131
查看次数

Pytest 装置不应该直接调用

我想在 conftest.py 中设置一个固定装置,并与我的所有测试共享它。但是,在以下最小示例上运行 pytest 时遇到以下错误:

ERROR at setup of test_test 
Fixture "pytest_runtest_setup" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
Run Code Online (Sandbox Code Playgroud)

conftest.py

import pytest
import os


@pytest.fixture
def pytest_runtest_setup():
    print("hello ? ---------------------------------")
Run Code Online (Sandbox Code Playgroud)

test.py

import pytest


def test_test():
    assert True
Run Code Online (Sandbox Code Playgroud)

pytest.ini

[pytest]
addopts = -rA -v -p no:faulthandler -W ignore::DeprecationWarning
Run Code Online (Sandbox Code Playgroud)

Pytest 启动时使用pytest test.py

没有任何地方直接调用fixture函数,甚至在示例测试中也没有使用它。那么为什么 pytest 会抛出这个问题以及如何在 conftest.py 中声明和使用固定装置?

环境:

  • Python 3.8.3
  • pytest-6.1.2

python pytest python-3.x

5
推荐指数
1
解决办法
6889
查看次数

Python selenium不能与WebDriverWait一起使用

我尝试用selenium登录google.如果我像这个代码一样使用sleep(),它会起作用

browser = webdriver.Firefox()
browser.get('https://admin.google.com/')

emailElem = browser.find_element_by_id('Email')
emailElem.send_keys('mymail')
nextButton = browser.find_element_by_id('next')
nextButton.click()

sleep(5)
passwordElem = browser.find_element_by_id('Passwd')
passwordElem.send_keys('mypass')
signinButton = browser.find_element_by_id('signIn')
signinButton.click()
Run Code Online (Sandbox Code Playgroud)

如果我像这样将睡眠改为WebDriverWait

browser = webdriver.Firefox()
browser.get('https://admin.google.com/')

emailElem = browser.find_element_by_id('Email')
emailElem.send_keys('mymail')
nextButton = browser.find_element_by_id('next')
nextButton.click()


passwordElem = WebDriverWait(browser, 5).until(
    EC.presence_of_element_located(browser.find_element_by_id('Passwd'))
)
passwordElem.send_keys('mypass')
signinButton = browser.find_element_by_id('signIn')
signinButton.click()
Run Code Online (Sandbox Code Playgroud)

它显示这样的错误.

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="Passwd"]
Run Code Online (Sandbox Code Playgroud)

如何使用WebDriverWait?

python selenium selenium-webdriver

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