selenium-webdriver

How to find elements without using the tag attribute?

倾然丶 夕夏残阳落幕 提交于 2020-06-16 17:25:42
问题 image = driver.find_elements_by_xpath("//img[contains(@class,'ui_qtext')]") copy = driver.find_elements_by_xpath("//p[contains(@class,'ui_qtext')]") I have this two elements with different tag_names. How do i locate them without the tag_name? Or how do i "combine" this two? Both have the same class_name. 回答1: To remove the dependency on the tagNames you can use either of the following Locator Strategies: Using xpath : image_copy = driver.find_elements_by_xpath("//*[contains(@class,'ui_qtext')

How to call parent class init with default values from child class?

时光总嘲笑我的痴心妄想 提交于 2020-06-16 16:10:32
问题 I am trying to give my subclasses default variables and stop duplicating code as the file is getting fat: class Base(object): def __init__(self, username=None, password=None, start_url=None): self.username = username self.password = password self.start_url = start_url class Subclass(Base): def __init__(self, username="hoss_it87", password="whatsgoodSO", start_url="www.boss-sauce.com"): super(Subclass, self).__init__() Base works of course, but I want Subclass to init the same way, just

Exception in thread “main” java.lang.NoClassDefFoundError: com/google/gson/JsonParseExceptiong

心不动则不痛 提交于 2020-06-16 09:37:47
问题 I have encountered the following error "Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/JsonParseException", when running selenium script in TestNg. How to resolve this error? 回答1: I have came across the same "NoClassDefFoundError:com/google/gson/JsonParseException" error before. This was caused by the addition of "selenium-java-2.53.0" jar file in my package. I removed this jar file and refreshed my project and ran again. It was working fine there after. You can

Is there any alternative for PageFactory using net core

淺唱寂寞╮ 提交于 2020-06-16 04:17:29
问题 I'm using Selenium v3.6.0 and .NET Core 2.0, the following code gives me an error on PageFactory.InitElements saying it doesn't exist in the currenct context. using OpenQA.Selenium; using OpenQA.Selenium.Support.PageObjects; namespace Example { public class Form { [FindsBy(How = How.Name, Using = "Filter")] // This does exist in current context using .NET Core public IWebElement Filter { get; set; } [FindsBy(How = How.TagName, Using = "Button")] public IWebElement Button; public Form

Is there any alternative for PageFactory using net core

微笑、不失礼 提交于 2020-06-16 04:17:27
问题 I'm using Selenium v3.6.0 and .NET Core 2.0, the following code gives me an error on PageFactory.InitElements saying it doesn't exist in the currenct context. using OpenQA.Selenium; using OpenQA.Selenium.Support.PageObjects; namespace Example { public class Form { [FindsBy(How = How.Name, Using = "Filter")] // This does exist in current context using .NET Core public IWebElement Filter { get; set; } [FindsBy(How = How.TagName, Using = "Button")] public IWebElement Button; public Form

Selenium: Save and Load LocalStorage to/from File

不羁岁月 提交于 2020-06-13 08:32:25
问题 I'm currently writing a script in python to tell me how many unread messages I have in WhatsApp. To get the count of unread messages selenium opens web.whatsapp.com however I have to authenticate every time. I found out that WhatsApp saves the data to authenticate in the LocalStorage so I'm trying to figure out how I can save the contents from LocalStorage to a file and then later read from it and set all the keys. I tried: localStorage = driver.execute_script('return window.localStorage;')

Default location of ChromeDriver binary and Chrome binary on windows 7

怎甘沉沦 提交于 2020-06-13 05:34:27
问题 What is the default location of ChromeDriver binary and Chrome binary on windows 7 for triggering appium using java-client.jar? if i am using RemoteWebDriver and tries to initiate chrome browser, from where does the selenium initiates the chromedriver? the code: DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("userName", ReadProperties.Properties("MobileUsername")); capabilities.setCapability("password", ReadProperties.Properties("MobilePassword"));

Making program using Chromedriver, getting error: “Could not get version for Chrome with this command”

独自空忆成欢 提交于 2020-06-12 07:46:47
问题 This is my code. I am doing it this way because when I tried to put a path to chromedriver.exe, I was either getting "WebDriverException: Message: 'chromedriver.exe' executable may have wrong permissions" or "WebDriverException: Message: 'chromedriver' executable needs to be in PATH" and I could not figure out how to fix it. from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager browser = webdriver.Chrome(ChromeDriverManager().install()) Running this code

Give upload file path to Instagram with Selenium and python

独自空忆成欢 提交于 2020-06-12 07:46:08
问题 I'm testing some web scraping on Instagram with Selenium and Python. In this case I want to upload a picture. Normally you have to click on the upload icon and choose the file from a window. How can I manage it with Selenium? I tried: driver.find_element_by_class_name("coreSpriteFeedCreation").send_keys('C:\\path-to-file\\file.jpg') and also with find_element_by_xpath but I get an exception: selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element I tried

Selenium WebDriver get_attribute returns truncated value of href attribute when value has entities

吃可爱长大的小学妹 提交于 2020-06-12 06:47:25
问题 I am trying to get href attribute value from anchor tab on a page in my application using selenium Webdriver (Python) and the result returned has part stripped off. Here is the HTML snippet - <a class="nla-row-text" href="/shopping/brands?search=kamera&nm=Canon&page=0" data-reactid="790"> Here is the code I am using - from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Firefox() driver