Normal view
- Atata - C# Web Test Automation FrameworkAn introduction to Atata C#/.NET web UI test automation full-featured framework based on Selenium WebDriver
- selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() with urls read from text file with Selenium PythonI have a list of URLs in a .txt file that I would like to run using selenium. Lets say that the file name is b.txt in it contains 2 urls (precisely formatted as below): https://www.google.com/,https://www.bing.com/, What I am trying to do is to make selenium run both urls (from the .txt file), however it seems that every time the code reaches the "driver.get" line, the code fails. url = open ('b.txt','r') url_rpt = url.read().split(",") options = Options() options.add_argument('--headless')
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() with urls read from text file with Selenium Python
I have a list of URLs in a .txt file that I would like to run using selenium.
Lets say that the file name is b.txt in it contains 2 urls (precisely formatted as below): https://www.google.com/,https://www.bing.com/,
What I am trying to do is to make selenium run both urls (from the .txt file), however it seems that every time the code reaches the "driver.get" line, the code fails.
url = open ('b.txt','r')
url_rpt = url.read().split(",")
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=options)
for link in url_rpt:
driver.get(link)
driver.quit()
The result that I get when I run the code is
Traceback (most recent call last):
File "C:/Users/ASUS/PycharmProjects/XXXX/Test.py", line 22, in <module>
driver.get(link)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-
packages\selenium\webdriver\remote\errorhandler.py", line 242, in
check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid
argument
(Session info: headless chrome=79.0.3945.117)
Any suggestion on how to re-write the code?
- How can I switch from headless mode to normal mode using Google Chrome and Selenium?I am looking for a solution to open the chrome browser with selenium in headless mode, do some actions and then switch within the same browser in normal mode. For example: from selenium import webdriver from selenium.webdriver.common.keys import Keys chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("headless") browser = webdriver.Chrome('C:/chromedriver', options=chrome_options) browser.get("https://www.google.de/") # Do some actions in headless mode browser.find_eleme
How can I switch from headless mode to normal mode using Google Chrome and Selenium?
I am looking for a solution to open the chrome browser with selenium in headless mode, do some actions and then switch within the same browser in normal
mode.
For example:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("headless")
browser = webdriver.Chrome('C:/chromedriver', options=chrome_options)
browser.get("https://www.google.de/")
# Do some actions in headless mode
browser.find_element_by_css_selector("#L2AGLb > div").click()
browser.find_element_by_css_selector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input").send_keys("Python rocks")
browser.find_element_by_css_selector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.FPdoLc.lJ9FBc > center > input.gNO89b").send_keys(Keys.ENTER)
# Open Browser
Is there a way to do this?
- io.cucumber.junit.UndefinedStepException: The step "User is in login page" is undefined. You can implement it using the snippet(s) below:I have the following error: but I have implemented the steps enter image description here How I can do?
- Problem with selenium does not load page after some timeI have made a simple code, which I scrape recipes from one site. The url of every recipe is written on an excel and I read it with pandas. I have a weird problem there, for example I want to scrape 100 recipes, when the for goes to i = 21 it breaks and does not load the page (infinite loading of the site), but when I start the for loop from 20 it breaks on 41. Rerun the code and can break on i = 17, it's pretty random. Does anyone has this similar problem? website: https://akispetretzikis.com/en
Problem with selenium does not load page after some time
I have made a simple code, which I scrape recipes from one site. The url of every recipe is written on an excel and I read it with pandas. I have a weird problem there, for example I want to scrape 100 recipes, when the for goes to i = 21 it breaks and does not load the page (infinite loading of the site), but when I start the for loop from 20 it breaks on 41. Rerun the code and can break on i = 17, it's pretty random. Does anyone has this similar problem? website: https://akispetretzikis.com/en thank you
def mainProgram(start):
now = datetime.now()
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('--no-sandbox')
options.add_argument('--disable-infobars')
options.add_argument('--disable-dev-shm-usage')
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
theDictionary = {"Link": [], "Name": [], "Time": [], "Difficulty": [],
"Merides": [], "Ingredients": [],
"ThermidesPer100gr": [], "ThermidesAnaMerida": []}
driver = webdriver.Chrome(executable_path=r'/usr/lib/chromium-browser/chromedriver',
options=options)
driver.set_window_size(1280, 960)
thePath = os.path.join(os.path.expanduser("~"), "Desktop", "ScrapeRecipes",
"Cooking"+str(now.year)+".xlsx")
thePathReadExcel = os.path.join(os.path.expanduser("~"), "Desktop",
"CookingUrls"+str(now.year)+".xlsx")
UrlOfRecipes = readExcel(thePath=thePathReadExcel)
try:
Length = len(UrlOfRecipes)
print(Length)
Length = 100#e.g. 100 actual Length over 1k
for i in range(start, Length, 1):
driver.delete_all_cookies()
driver.get(UrlOfRecipes["Link"][i])
wait = WebDriverWait(driver, 20 + round(random.uniform(0, 4), 2))
time.sleep(30 + round(random.uniform(0, 4), 2)) # mandatory sleep
theDictionary["Link"].append(UrlOfRecipes["Link"][i])
theDictionary = getDataFromRecipe(driver, theDictionary)
time.sleep(20 + round(random.uniform(0, 4), 2))
print(i)
except Exception as e:
print(e)
writeOnExcel(theDict, thePath)
- 'data:,' in the address bar while using chromedriver 2.19 and selenium 2.47Issue Description: When I'm starting the test I see data:, in the chrome address bar and after few seconds the Chrome window get closed instead of starting navigating to the URL. OS & Chrome info: ChromeDriver:- 2.19 Chrome:- 44.0.2403.157 Selenium:- 2.47 Windows 7: 32 bit. Steps to reproduce: Running simple test that is trying to navigate a web page using driver.get(...) method. Once the test is started, the console displays the below mentioned message "Starting ChromeDriver 2.19.33
'data:,' in the address bar while using chromedriver 2.19 and selenium 2.47
Issue Description:
- When I'm starting the test I see
data:,
in the chrome address bar and after few seconds the Chrome window get closed instead of starting navigating to the URL.
OS & Chrome info:
- ChromeDriver:- 2.19
- Chrome:- 44.0.2403.157
- Selenium:- 2.47
- Windows 7: 32 bit.
Steps to reproduce:
- Running simple test that is trying to navigate a web page using
driver.get(...)
method.
Once the test is started, the console displays the below mentioned message
"Starting ChromeDriver 2.19.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961) on port 56002 Only local connections are allowed."
Later, I see data:,
in the Chrome address bar and it just keeps loading for more than 10 minutes but does not navigate to the given URL.
Leveraging Selenium, NUnit and C# for UI tests
- Webdriver : How to switch to a specific window?I came across many solutions for switching between windows, one of them is: Set<String> allWindows = driver.getWindowHandles(); for(String currentWindow : allWindows){ driver.switchTo().window(currentWindow); } But, I am unable to go to a particular window. Can someone tell me how to switch to 3rd window from parent window (using java client library)?
Webdriver : How to switch to a specific window?
I came across many solutions for switching between windows, one of them is:
Set<String> allWindows = driver.getWindowHandles();
for(String currentWindow : allWindows){
driver.switchTo().window(currentWindow);
}
But, I am unable to go to a particular window. Can someone tell me how to switch to 3rd window from parent window (using java client library)?
- Selenium not freeing up memory even after calling close/quitSo I've been working on scraper that goes on 10k+pages and scrapes data from it. The issue is that over time, memory consumption raises drastically. So to overcome this - instead of closing driver instance only at the end of scrape - the scraper is updated so that it closes the instance after every page is loaded and data extracted. But ram memory still gets populated for some reason. I tried using PhantomJS but it doesn't load data properly for some reason. I also tried with the initial version
Selenium not freeing up memory even after calling close/quit
So I've been working on scraper that goes on 10k+pages and scrapes data from it.
The issue is that over time, memory consumption raises drastically. So to overcome this - instead of closing driver instance only at the end of scrape - the scraper is updated so that it closes the instance after every page is loaded and data extracted.
But ram memory still gets populated for some reason.
I tried using PhantomJS but it doesn't load data properly for some reason. I also tried with the initial version of the scraper to limit cache in Firefox to 100mb, but that also did not work.
Note: I run tests with both chromedriver and firefox, and unfortunately I can't use libraries such as requests, mechanize, etc... instead of selenium.
Any help is appreciated since I've been trying to figure this out for a week now. Thanks.
- Running Automation Tests at Scale Using SeleniumIn this article, we will learn how to set up a Selenium WebDriver with Java and run the web automation tests (in series and parallel) on the LambdaTest cloud grid.
Running Automation Tests at Scale Using Selenium
- Running Automation Tests at Scale Using JavaScriptThis tutorial will discuss using Selenium with JavaScript for automated testing of websites and web applications.
Running Automation Tests at Scale Using JavaScript
- Running Automation Tests at Scale Using JavaThis post will discuss Selenium, how to set it up, and how to use Java to create an automated test script.
Running Automation Tests at Scale Using Java
- How to Automate Saving Webpages as a Single .MHTML Files using Selenium WebdriverSaving webpages in single self contained files using Selenium Webdriver
How to Automate Saving Webpages as a Single .MHTML Files using Selenium Webdriver
- Running Automation Tests at Scale Using PythonThis article discusses running automation tests at scale using Python, primarily focusing on Selenium.
Running Automation Tests at Scale Using Python
- Running Automation Tests at Scale Using PythonThis article discusses running automation tests at scale using Python, primarily focusing on Selenium.
Running Automation Tests at Scale Using Python
- Screenshot isn't attached to allure results folder and in the allure reportScreenshot isn't attached to allure results folder and in the allure report. I don't understand what's the problem. Have tried to add listeners in testng.xml and in the test class above the test name - no difference-> the png file isn't shown in the allure results when the test is failed. What am I doing wrong? public class AllureReportListener implements ITestListener { @Attachment(value = "Page screenshot", type = "image/png") public byte[] saveScreenshotPNG (WebDriver driver) {
Screenshot isn't attached to allure results folder and in the allure report
Screenshot isn't attached to allure results folder and in the allure report. I don't understand what's the problem. Have tried to add listeners in testng.xml and in the test class above the test name - no difference-> the png file isn't shown in the allure results when the test is failed. What am I doing wrong?
public class AllureReportListener implements ITestListener {
@Attachment(value = "Page screenshot", type = "image/png")
public byte[] saveScreenshotPNG (WebDriver driver) {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
@Override
public void onStart(ITestContext iTestContext) {
System.out.println("Starting Test Suite '" + iTestContext.getName() + "'.......");
iTestContext.setAttribute("WebDriver", BaseTest.getDriver());
}
@Override
public void onFinish(ITestContext iTestContext) {
System.out.println("Finished Test Suite '" + iTestContext.getName() + "'");
}
@Override
public void onTestStart(ITestResult iTestResult) {
System.out.println("Starting Test Method '" + getTestMethodName(iTestResult) + "'");
}
@Override
public void onTestSuccess(ITestResult iTestResult) {
System.out.println("Test Method '" + getTestMethodName(iTestResult) + "' is Passed");
}
@Override
public void onTestFailure(ITestResult iTestResult) {
System.out.println("Test Method '" + getTestMethodName(iTestResult) + "' is Failed");
if (BaseTest.getDriver() != null) {
System.out.println("Screenshot has captured for the Test Method '" + getTestMethodName(iTestResult) + "'");
saveScreenshotPNG(BaseTest.getDriver());
}
}
@Override
public void onTestSkipped(ITestResult iTestResult) {
System.out.println("Test Method '" + getTestMethodName(iTestResult) + "' is Skipped");
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {
}
private static String getTestMethodName(ITestResult iTestResult) {
return iTestResult.getMethod().getConstructorOrMethod().getName();
}
}
- Selenium IDE - Upload file into fieldI'm creating a testing suite to automate some parts of data input on my web application. I have a page where I can click on a button to upload a document to the application. It looks something like this: Once the Add New Attachment button is clicked, it opens the browser's file explorer to select a document to upload. I'm trying to replicate this within Selenium IDE. Here is what it looks like as of now: However, this part seems to fail. Does anyone know how to achieve a similar process u
Selenium IDE - Upload file into field
I'm creating a testing suite to automate some parts of data input on my web application. I have a page where I can click on a button to upload a document to the application. It looks something like this:
Once the Add New Attachment button is clicked, it opens the browser's file explorer to select a document to upload. I'm trying to replicate this within Selenium IDE.
Here is what it looks like as of now:
However, this part seems to fail. Does anyone know how to achieve a similar process using Selenium IDE? I'm on Chrome and Firefox.
- How to get exact date from Linkedin's post while inspecting site with selenium?i am using selenium chrome driver to scratch Linkedin's profile. I am doing analysis for my post. It is the way to get exact date from Linkedin's post in format "dd.mm.yyyy" instead of "1 month ago", "2 weeks ago"? Please help, Jacek
How to get exact date from Linkedin's post while inspecting site with selenium?
i am using selenium chrome driver to scratch Linkedin's profile. I am doing analysis for my post. It is the way to get exact date from Linkedin's post in format "dd.mm.yyyy" instead of "1 month ago", "2 weeks ago"?
Please help, Jacek