DesiredCapabilities is obsolete in Selenium Web Driver V.3.14 How to write the code for Selenium grid in C#?

I have the following code. I update the selenium web driver to v3.14 and it shows the obsolete and error messages.

DesiredCapabilities capabilities; –deprecated

capabilities = DesiredCapabilities.Chrome(); –has the error for Selennium wen driver v3.14

capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));

Uri uri = new Uri(hub url);

_driver = new RemoteWebDriver(uri, capabilities, TimeSpan.FromSeconds(120));

From class RemoteWebDriver in OpenQA.Selenium.Remote, it still has the ICapabilities parameter

public RemoteWebDriver(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout);

I saw some posts using Chrome options. But I still cannot make it work for selenium grid. Any idea?

Thanks,

Ray

All topic

What should be the approach to test styles using Selenium

In my UI tests I would like to verify particular style values for the elements. Below is the example list of the styles I’d like to verify:

  • font style
  • font size
  • padding
  • margin

Is there a way to do that using Selenium?

All topic

Python selenium how to get only paragraphs with text

Imagine I have such html:

Sometext

More text

Using selenium, is there a way to get only paragraphs which contain text? In example it will be the first and the fourth paragraphs..

All topic

Selenium unable to compose letter with accent using SendKeys

I want to let the input field compose an accent based on the input of Selenium.

Some examples:

  • ^+o should result in ô
  • ^+i should result in ï
  • ~+n should result in ñ

Note if I used SendKeys("ô") or any other already composed key it works but this is not what I want to do.

  • In Firefox I get ^o, ^i and ~n

  • In Chrome I get o, i, n

C#

ChromeDriver ffDriver = new ChromeDriver();
ffDriver.Navigate().GoToUrl("http://localhost:8081/");
var element = ffDriver.FindElementById("input-text"); 

element.SendKeys("^i"); // doesn't work, splitting them up in 2 seperate calls also doesn't work
new Actions(ffDriver).SendKeys(element, "^i").Perform(); // also doesn't work

html:


All topic

Can’t drag and drop from source to target using selenium and python

I am trying to drag and drop using Python and Selenium.

I have two containers with rows which indicate file names and by drag and drop i want to transfer one file from the first container to the second one.

This is how containers look:
Containers

I have seen on the internet that selenium and drag and drop libraries had some issues and i am not really sure how to make this work.

As the version of browsers and drivers play an important role, please have a look at the ones I am using:
Drivers / Browsers versions

The way i am trying to drag and drop is the following:

time.sleep(15)
source_element = self.browser.find_element_by_css_selector('#transfer-tape-listing-nst0 > tbody > tr.file.transfer-tape-item.ui-draggable.ui-draggable-handle > td.listing-name')
dest_element = self.browser.find_element_by_css_selector('#transfer-location-listing > tbody > tr:nth-child(3) > td.listing-name.ui-droppable > span.listing-name-label')
ActionChains(self.browser).drag_and_drop(source_element, dest_element).perform()

My driver has this configuration:

def set_up_browser():
    display = Display(visible=0, size=(1200, 800))
    display.start()
    selected_browser = config_section_map('Test')['browser']
    browser = ''

    if selected_browser == 'Firefox':
        opts = FirefoxOptions()
        opts.add_argument("--headless")
        firefox_profile = webdriver.FirefoxProfile()
        firefox_profile.set_preference("browser.privatebrowsing.autostart", False)
        firefox_profile.set_preference("marionette", True) # remove if causing issues

        browser = webdriver.Firefox(executable_path="/usr/bin/drivers/geckodriver", firefox_profile=firefox_profile, firefox_options=opts)
    elif selected_browser == 'Chrome':
        opts = ChromeOptions()
        opts.add_argument("--headless")
        opts.add_argument("--no-sandbox")
        opts.add_argument("--incognito")
        browser = webdriver.Chrome(executable_path="/usr/bin/drivers/chromedriver", chrome_options=opts)
    elif selected_browser == 'edge':
         pass
    else:
        print 'unsupported browser'
        exit

    browser.set_window_size(1200, 800)
    browser.maximize_window()
    browser.delete_all_cookies()
    browser.implicitly_wait(int(config_section_map('Test')['wait']))
    browser.refresh()

    return browser

Can someone help me please with resolving this using Python? I have tried with both drivers and both fail. I don’t get any exception, but the action doesn’t work.

Thanks.

All topic

Selenium script on Pega Platform application behaves weird

I have identified web elements uniquely using customized xpath

//table[@pl_prop_class='SOM-FW-PayMaineFW-Data-ProductGroup']/tbody/tr/th[1]/div/div/div[1]

But, when I run the test script and perform getText() with it Selenium gives me error: NoSuchElement

When i evaluate my xpath in Mozilla, it does show me the header text highlighted as expected. How do I go about identifying headers of columns in this table?

All topic

python + selenium + chromeでHTMLを読み込みたい

https://www.coin-laundry.co.jp/userp/shop_detail/10000543.html
上記サイトから稼働状況のテーブルを抜き出したいと考えています。

テーブル部分がjavascriptで生成されているようなので、headlessブラウザ(Chrome)をseleniumから操作して取得しようとコードを書いてみました。

import time

from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-desktop-notifications')
options.add_argument("--disable-extensions")
options.add_argument('--allow-running-insecure-content')
options.add_argument('--disable-web-security')
options.add_argument('--no-sandbox')
options.add_argument('--lang=ja')
options.add_argument('--window-size=1200x600')
driver = webdriver.Chrome(chrome_options=options)

# URLを開く
TARGET = 'https://www.coin-laundry.co.jp/userp/shop_detail/10000543.html'

driver.get(TARGET)

time.sleep(2)  # とりあえず適当に2秒待つ。

page_source = driver.page_source
html = BeautifulSoup(page_source, 'html.parser')
print(html)

driver.quit()  # ブラウザーを終了する。

このコードを実行すると、最初に書いたサイトに限り


としか返ってきません。
javascriptをレンダリングする前のHTMLも取得できません。
time.sleep()の時間も色々変えてみましたが、結果は同じ。
TARGETの部分を他のURLにした場合は、ちゃんとHTMLコードが出力されます。

selenium + Phantomjs2.1.1 や casperjs + Phantomjs2.1.1も試してみましたが、結果は同様でうまく取得できませんでした。

実行環境は
サーバ AWS EC2
OS Ubuntu 16.04
Python 3.5.2
selenium
Google Chrome 60.0.3112.90
BeautifulSoup4
node 8.2.1

最初はPhantomjsを使ってやっていたのですが、上記サイトだけどうしても取得できませんでした。ブラウザの問題かと思い、リモートデスクトップでUbuntu上のChromeでアクセスしたところ、普通に表示ました。なのでChromeのHeadlessモードなら通常モードと同じように取得できると思ったのですが・・・。

八方塞がりで途方に暮れている次第です。
よろしくお願いいたします。

All topic

How to use class and text attribute together in CSS selector in selenium

Please visit the URL https://accounts.google.com/signin/v2/identifier?

Observe that there is a Next button. I want to click it using only Css selector.

I use below code to get element

driver.findElement(By.cssSelector(“span.RveJvd.snByac”))

span.RveJvd.snByac is also used for Forgot email? button so this is getting clicked.

Is there a way to combine class and the text ‘Next’ attributes of Next button ?

Note : I have to use only Css selector.

All topic

How do I switch focus to a new window using Selenium VBA?

So, I know how to find the name of the active window

currentWindow = bot.Send("GET", "/window_handle")
bot.SwitchToWindowByName currentWindow

Is there a way to get the name of the inactive window that I just popped up?

I tried going to console and typing window.name and got “”
Also tried using window.document.name and got “download.phtml”, but

bot.SwitchToWindowByName download.phtml

gave me a Runtime 424 Object Required error.

Picture of the new window (on the right)

All topic

Selenium search in google then scan page if search word exist

1.
I’m using Selenium to search for “sage release dates” in google.

2.
Then I want to scan the entire results page if my search word “release date” exists in the results.

I’m reusing this search pattern code from a previous project of mine but that one used urllib. So I had to adjust the search pattern code slightly. But it doesn’t do what I want. I’m stuck. Can somebody point me in the right direction?

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
import re

#   Version Alpha 3
#_______________________________________________________________________________

browser = webdriver.Chrome(executable_path=r"C:Selenium_Driverschromedriver.exe")
browser.get('http://www.google.com')

input_element = browser.find_element_by_name('q')
input_element.send_keys('sage release dates')
# input_element.send_keys('Wolters Kluwer release dates')
input_element.submit()

'''
RESULTS_LOCATOR = '//div/h3/a'

WebDriverWait(browser, 10).until(
    EC.visibility_of_element_located((By.XPATH, RESULTS_LOCATOR)))

page1_results = browser.find_elements(By.XPATH, RESULTS_LOCATOR)
'''

page1_results = browser.find_elements_by_class_name('med')

for item in page1_results:
    print(item.text)

#..................................................

keywords = ['release date']

# sequence = page1_results.decode('utf-8', 'ignore')
sequence = page1_results

for k in keywords:
    pattern = '(?i)' + k
    keyword = re.search(pattern, str(sequence))
    if keyword:
        # print(keyword.group(0))
        print('k-1')
        print(k)
        print(keyword)
    else:
        print('k-2')
        print('-')
        print(k)
        print(keyword)




#..................................................
# browser.quit()

All topic