Popup not opening on button click chrome headless on linux - java

I am automating one test case where I clicks on Add key button on bit bucket and open popup as per below screenshot :
Somehow this popup is not opening when I run my script using jenkins on linux AWS.
I am using Selenium Webdriver , Java, Chrome Headless and maven.
Here is my settings in code for chrome headless :
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
chromePath = System.getProperty("user.dir") + prop.getProperty("chromeDriverPath");
System.setProperty("webdriver.chrome.driver", chromePath);
options.addArguments("--headless");
options.addArguments("--start-maximized");
options.addArguments("--window-size=1366,768");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-gpu");
options.addArguments("--dns-prefetch-disable");
options.addArguments("--always-authorize-plugins");
options.addArguments("enable-automation");
options.addArguments("--disable-browser-side-navigation");
options.setPageLoadStrategy(PageLoadStrategy.NONE);
driver = new ChromeDriver(options);
Am I missing any other argument which can help me to resolve this issue?
Html Code of button where clicked and open popup :
<div class="buttons">
<button class="aui-button aui-button-primary" id="add-key" resolved="">Add key</button>
</div>
Screenshot of Html :

As per the HTML you have shared to invoke click() on the element with text as Add key you can use the following solution:
It seems that that some of the elements are dynamically generated, ideally instead of PageLoadStrategy.NONE you need to use PageLoadStrategy.NORMAL as follows:
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
Induce WebDriverWait for the element to be clickable as follows:
CSS_SELECTOR:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.aui-button.aui-button-primary#add-key"))).click();
XPATH:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='aui-button aui-button-primary' and #id='add-key'][text()='Add key']"))).click();

Related

Selenium click element & Action drag and drop is not working in edge browser using java

Selenium click element & Action drag and drop is not working in edge browser using java
where as same code base works with Chrome & firefox browser without any issue . Facing issue only with edge browser.
Sample Code Snippet :
Driver Setup :
ThreadLocal<WebDriver> driver= new ThreadLocal<>();
WebDriverManager.edgedriver().setup();
EdgeOptions edgeOptions = new EdgeOptions();
driver.set(new EdgeDriver(edgeOptions));
Click :
WebElement ele = DriverUtil.getInstance().getDriver().findElement(By.xpath("//div[contains(#class,'menu-overlay')]");
ele.click();
Drag & Drop Action :
WebElement ele = DriverUtil.getInstance().getDriver().findElement(By.xpath("//div[contains(#class,'b-sch-cell')]");
Actions action = new Actions(DriverUtil.getInstance().getDriver());
action.dragAndDropBy(ele, 165, 30).build().perform();
Any idea/help/reference link would be much appreciated..
Thanks in advance ...

ChromeDriver with Selenium displays a blank page

I am using Selenium(Java) with Chrome to access the following website:
https://www.ebay-kleinanzeigen.de/m-einloggen.html?targetUrl=/
The Problem is that it always displays a blank page. Here is my Code:
ChromeOptions cap = new ChromeOptions();
cap.setBinary("C:\\Program Files (x86)\\Google\\Chrome Beta\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Downloads\\chromedriver_win32beta\\chromedriver.exe");
WebDriver driver=new ChromeDriver(cap);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
try {
driver.get("https://www.ebay-kleinanzeigen.de/m-einloggen.html?targetUrl=/");
}catch(Exception e){
System.out.println(e);
}
Every other website I have tried works just fine, but this one doesn't want to show up. I have tried to access this website from Firefox, Chrome and Edge, which also show a blank page. I am using Selenium(3.141.59), ChromeDriver(81.0.4044.20) and Chrome Beta(81.0.4044.62).
Here is the HTML Code when I ispect the website:
It looks like this site can detect Selenium and do not open with it.
You can hide it using Chrome Options. Try adding arguments like this before openning the url:
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-blink-features=AutomationControlled");
ChromeDriver driver = new ChromeDriver(options);
Hope this helped, good luck!
It works with selenium stealth and the following options
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
I experienced the same issue. Check if the page you requested returns a successful HTTP status code like 200. In my case, it returned a 40x error which resulted in a blank page.

Internet Explorer not selecting Elements on Webpage

I am running Selenium to test a specific area of my companies webpage. What I am trying to do seems relatively easy in theory, but I have ran into several obstacles. Can someone please tell me why the URL is opening but won't select the "Services" Hyperlink?
Below is a snippet of the code:
System.setProperty("webdriver.ie.driver","Path to IE/IEDriverServer_64.exe");
WebDriver driver = new InternetExplorerDriver();
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
driver.get("https://www.ups.com/us/en/Home.page");
driver.manage().window().maximize();
driver.findElement(By.xpath(".//*/div[#id='ups-header']/nav[#id='ups-navItems']/ul[#class='ups-navItems_primary']/li[#class='ups-navMenu ups-menu'][3]/a[#id='ups-menuLinks2']")).click();
As I stated earlier, in theory this should open up UPS's homepage and select the "Services" tab on the top right of the page. Instead it just goes to UPS.com homepage and stays there.
I have driver.findElement(By.xpath........); in this example but I have tried findElement(By.name & partialLinkText
Can anyone give me a solution besides update to latest version(s)?
Metadata:
Windows 10,
JAVA 10,
Internet Explorer (Unfortunately) 11.4.
Thanks in advance!
Edit with additonal HTML structure:
This is a portion of the HTML I am working with. This HTML belongs to the Services link I want to click in my automation:
<a role="button" href="#" class="ups-analytics ups-menu_toggle" data-
content-block-id="M1" data-event-id="22" aria-expanded="false" id="ups-
menuLinks2" aria-controls="ups-menuPanel2">Services<span class="ups-mobnav-
arrow" aria-hidden="true"></span></a><div class="ups-menu_list ups-cols-3"
aria-hidden="true" role="region" id="ups-menuPanel2" aria-labelledby="ups-
menuLinks2">
<h2 class="ups-med_show">Services</h2>
<div class="ups-menu_listCols">
Internet Explorer v11 doesn't opens the url on my system but with Selenium v3.12.0, ChromeDriver 2.39 and Chrome v67.0 the following solution clicks on the element with text as Services just perfecto:
Code Block:
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.ups.com/us/en/Home.page");
driver.findElement(By.linkText("Services")).click();
Browser Snapshot:
This was tricky for IE , for some reasons all the xpath i tried seems to not work. This might be due to some capabitlites that needs to be added. I haven't looked into it in details but its working for me in Firefox:
String baseURL = "https://www.ups.com/us/en/Home.page";
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "//path to//geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(baseURL);
Thread.sleep(3000);
WebElement service=driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/div/div/div/header/div/nav/ul[1]/li[3]"));
System.out.println(service.getText());
service.click();
If you have issues with your Firefox. Please share the stacktrace so we can help. This code perfectly works for Firefox

Selenium can't click on element, because of overlay

I can't click on element, because of overlay appears. Try to use capability to scroll to element and set it in bottom. Does not work for me.
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);
RemoteWebDriver driver = new ChromeDriver(options);
Can we do it in another way using java, chrome options (except js)?
chromedriver 2.36
selenium 3.11.0
testNG 6.14.2
If something overlays on top of the element you want to click then use actions method to move to the element which will make it enable to click and then click. This should work:
Actions actions1 = new Actions(driver);
actions1.moveToElement(youElement);
actions1.click();
actions1.build().perform();

Not able to click on a button in selenium webdriver

webDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.xpath("html/body/div[1]/section[1]/div/div/a/button")).submit();
'View positions' button is not clicking with the above code.What is happening in the web page?
You see the HTML for this page is
So, you can use the CSS selector for this as
WebDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.cssSelector("button.button.teal").click();
And then proceed with doing whatever is necessary. I executed with this in my Python code and it works fine.
Also, you will need to provide the Gecko executable path while calling for the FirefoxDriver()
The way I have done it before is to use the click handler.
driver.findElement(By.cssSelector(".profile-actions .primary_button > span")).click();
I'm sure you could also select the element by xpath rather than CSS in the above line. It's a similar question to this one.

Categories

Resources