xpath is not working in HtmlUnitDriver - java

I am using XPath, HtmlUnitDriver & FirefoxDriver.
Here is the my xpath to click on the signin button. When I use XPath
//div[#id='mainPane']/form/table/tbody/tr[10]/td/a[2]
to click on sign in button then it is working fine with FirefoxDriver but not working in HtmlUnitDriver.I have also enabled & disabled the javascript in HtmlUnitDriver.But not working.
I am getting Error:- When I click on this sign in button using HtmlUnitDriver,then it is not redirecting to next page,but in FirefoxDriver,it is redirecting to next page.Here is my code:-
HtmlUnitDriver driver = new HtmlUnitDriver(false);
WebElement webElement = webDriver.findElement(By.xpath("//div[#id='mainPane']/form/table/tbody/tr[10]/td/a[2]"));
webElement.click();
Please guide me.

As #David Grant suggests your problem might be related to the Javascript.
Enable your javascript in the HtmlUnitDrive -
HtmlUnitDriver driver = new HtmlUnitDriver(true);

Related

How to check remember_me checkbox of Jenkins login page using selenium?

I cannot check-in the user credentials encrypt/decrypt logic, to the git, so for now we are copying the class files on CI machines. But it has dependency to contact IT team for copy access.
Approach I am thinking is like - create a customer chrome profile, launch it using selenium chrome driver, on Jenkins login page, add user name, password and click remember me. I hope this setting will persisted to next chrome session as well. But, somehow the code is not able check the checkbox. It do identify it but no click.
I have tried by suing wait, maximize the window, still get the error as :
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element is not clickable at point (764, 504). Other element would receive the click: ...
Code I am using :
driver.get(input_params.get("JenkinsURL"));
driver.manage().window().maximize();
WebElement remember_me = driver.findElement(By.xpath("//*[#id='remember_me']"));
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
remember_me.click();
Please try with the below. It worked for me.
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().setScriptTimeout(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("URL");
WebElement checkbox = driver.findElement(By.xpath("/html/body/div/div/form/div[4]/label/div[1]"));
checkbox.click();
Please use the xpath as below:
//div[#class='Checkbox-indicator']//*[local-name(0='svg']

How to Automate new Facebook Sign up popup?

I've tried to Automate Facebook Signup page (new version consists of a popup). I've tried to switch to iframe but I've failed to find it.
Please help me. Please share the code.
The code below worked for me. Signup section is not any new pop-up window or frame. So don't need to switch to any frame or window. Just locate the fields and enter the required data using methods like sendKeys, clicks etc.
WebDriver Driver = new ChromeDriver();
Driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//Driver.manage().window().maximize();
String url = "https://www.facebook.com/";
Driver.get(url);
WebElement createAcount=Driver.findElement(By.id("u_0_2"));
createAcount.click();
WebElement firstname=Driver.findElement(By.id("u_1_b"));
firstname.sendKeys("Tina");
WebElement surname=Driver.findElement(By.id("u_1_d"));
surname.sendKeys("Roy");
I think Sign-up input fields are NOT in the iframe, so you don't need to switch.
Just doing this test. The elements are dynamically generated so they have different values everytime. Group the element selection by more attributes

Unable to automate HTML5 DragAndDrop in IE11

Are there any work around to make HTML5 Drag and Drop work in IE11 with Selenium Webdriver with java? I am using Selenium-Webdriver 3.4
Please find the attached for more details about the HTML. I have used the below Locator to locate the elements which works fine with Action class in chrome but not in IE11.
Web Element Initialisation
#FindBy(how = How.CSS, css =".work-card-description.searchable-field")
private WebElement weDragFrom;
#FindBy(how = How.CSS,css = "div.resource-schedule.resource-ui-droppable
div.hour-line:nth-of-type(11)")
private WebElement weDragTo;
Please find the Attached

Selenium web Driver retrieve response

how to retrieve response text generated in browser after executing script in selenium web drive.in the above figure the underlined response I want to retrieve and store it in a string.
//Opening the web page
driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "/usr/local/share/chromedriver");
driver.get(Mymark.str);
//Opening the login page
WebElement login= driver.findElement
(By.xpath("//a[text()='Log in']"));
login.click();
// Enter Username
WebElement Usrnm=driver.findElement
(By.xpath("//div[#id='mainContainer']//mymark-login[#class='x-scope mymark-login-0']//input[#name='uname']"));
Usrnm.sendKeys("nayazjh");
//Enter Password
WebElement Pswd= driver.findElement
(By.xpath("//div[#class='content']//div[#class='loginlayout layout vertical justified style-scope mymark-login']//input[#name='password']"));
Pswd.sendKeys("doordie");
//click on remember me button
driver.findElement(By.xpath( "//div[#id='toggleButton']")).click();
//Click on login button
WebElement logIn= driver.findElement
(By.xpath("//div[#class='lsubmitarea style-scope mymark-login']//paper-button[text()='Log in']"));
logIn.click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement
(By.xpath("//paper-button[text()='Add Bookmark Group ']")).click();
driver.findElement
(By.xpath("//paper-dialog[#id='addgroupdialog']//input[#id='input']")).sendKeys("selenium71");
element = driver.findElement
(By.xpath("//paper-dialog[#id='addgroupdialog']//div[#class='adddialogsubmit style-scope mymark-addgroup']" +
"//paper-button[#id='addgroupbutton']"));
element.click();
here i need a code to retrieve the response in java
}
1
The above image shows the response I want to get it using selenium or java
how to retrieve response text generated in browser after executing script in selenium web drive.in the above figure the underlined response I want to retrieve and store it in a string.
As far as I know it is impossible for selenium to get the actual response.
Selenium is build "on top". It can not directly control how the browser interacts with the server nor is it supposed to support this kind of control.
Selenium is thought as an ui automation framework, i.e. clicking and asserting ui state. It is not meant to intercept browser-server communication.

Unable to access link menu options using webdriver

I am using selenium webdriver. I am unable to access link menu options.eg:I want to access options "Casual shoes" option under "Men" menu link from flipkart site. i tried using below code
WebElement a= driver.findElement(By.xpath("//a[title='Men']"));
a.click();
but unable to click on menu link "Men"
Your XPath is wrong you forget to add # in front of attribute. You are using //a[title='Men'] but you should use //a[#title='Men']
Below code is working for me:-
driver.get("http://www.flipkart.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//a[#title='Men']")).click();
driver.findElement(By.xpath("//span[contains(.,'Casual Shoes')]")).click();
OR
In chrome below code is working fine for me:-
WebElement we =driver.findElement(By.xpath("//a[#title='Men']"));
we.click();
WebElement Causual =driver.findElement(By.xpath("//span[contains(.,'Casual Shoes')]"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", Causual);
Hope it will help you :)

Categories