Very new to Katalon Studio and selenium. Trying to write an automated test using selenium webdriver to change the value of the slider on the webpage.
I am failing to locate the element. Somehting is wrong with my findelement statement. Also once I locate the slider element successfully I don't know how to change the value of the slider. Can you help? or provide some quidance?
<div class="bdr-slider"
<span id="bdrText">bdr Amount</span>
<input min="0" max="15" step"0.5" value="5" type="range">
</div>
WebElement Slider = driver.findElement(By.xpath("*[div(#class,'bdr- slider')]"))
Try this :
WebElement Slider = driver.findElement(By.xpath("//div[#class='bdr-slider']"))
I'm not familiar with specifics of mobile automation, but I think that you need to locate the input element.
This one
<input min="0" max="15" step"0.5" value="5" type="range">
and then maybe call sendKeys method on that element.
You can try this line of code:
driver.findElement(By.xpath("//div[#class='bdr-slider']/input")).sendKeys("10");
Before proceeding, make sure the element is really present in the DOM, and thus making sure the problem is not with the path, enter $x('//div[#class="bdr-slider"]/input') to console in DevTools and see if you can locate the element.
If you can find the element, since you are using Katalon Studio, you can do this:
TestObject slider = new TestObject().addProperty('css', ConditionType.EQUALS, '.bdr-slider input')
or, if you prefer xpath:
TestObject slider = new TestObject().addProperty('xpath', ConditionType.EQUALS, "//div[#class='bdr-slider']/input")
You will need to import these two:
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
Related
I have to scrape this site and for that first I need to input data in the fields. I am using Selenium library for the task.
http://nhb.gov.in/OnlineClient/categorywiseallvarietyreport.aspx?enc=3ZOO8K5CzcdC/Yq6HcdIxJ4o5jmAcGG5QGUXX3BlAP4=
The page source has the following code in which I want to input the date in the Date input box.
<div style="float: right;">
<input name="ctl00$ContentPlaceHolder1$txtdate" type="text"
id="ctl00_ContentPlaceHolder1_txtdate" style="width:100px;" />
</div>
But there happens to be no value attribute and when I try to send input using the driver.send_keys() method nothing happens.
This is what I've tried but it doesn't work.
date = driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtdate")
date.send_keys('09/12/2018')
I have even tried mouse operations using ActionChains module but the Date input box is not clickable.
Is there anything that I'm doing wrong here?
I tried it your way, and it worked for me. Not sure why it's not working with you.
Here's the code I used with what you provided:
from selenium import webdriver
url = 'http://nhb.gov.in/OnlineClient/categorywiseallvarietyreport.aspx?enc=3ZOO8K5CzcdC/Yq6HcdIxJ4o5jmAcGG5QGUXX3BlAP4='
driver = webdriver.Chrome()
driver.get(url)
date = driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtdate")
date.send_keys('09/12/2018')
And it worked.
Maybe, try using .find_element_by_name and use "ctl00$ContentPlaceHolder1$txtdate" ??
url = 'http://nhb.gov.in/OnlineClient/categorywiseallvarietyreport.aspx?enc=3ZOO8K5CzcdC/Yq6HcdIxJ4o5jmAcGG5QGUXX3BlAP4='
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(url)
driver.find_element_by_name("ctl00$ContentPlaceHolder1$txtdate").send_keys('09/12/2018')
In selenium I have the following code
elem = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[#placeholder='Create new collab']")))
in order to select an input field inside the following construct:
<div class="md-input-container md-theme-default md-input-placeholder">
<label>Collab Name</label>
<input placeholder="Create new collab" class="md-input" type="text">
<!---->
<!---->
<!---->
::after
</div>
But I get a timeout exception after a wait for 10 seconds. Manually I am able to click and type something in that input field a second after is is being loaded.
The following ExpectedConditions are unable to find the element:
visibility_of_element_located
element_to_be_clickable
while this methid is able to find the element:
presence_of_element_located
but I am not able to use send_keys to the input field. I get an ElementNotInteractableException error. Also 'clicking' in the element before does not work - same error.
So what to try else?
The div with class - 'md-tabs-wrapper' has a style attribute - 'transform: translate3d(-748px, 0px, 0px);'. This div contains the input box that you are trying to interact. What the transform:translate3d does it is shift the divs and contents to the left and outside the viewport of the browser. You can test it by copying the relevant div in browser and then switching off this style or changing the values.
This kind off explains why the "presence" EC works but visibility and click EC do not. Apparently selenium is not able to figure that element is visible and thus throws the ElementNotInteractableException.
Use ActionChains instead. Use the element from the presence EC.
actions = ActionChains(driver)
actions.move_to_element(element)
actions.send_keys("hello world")
actions.perform()
Also need to clear the existing placeholder text for the sendkeys to work properly.
Try the following:
elem = driver.find_elements_by_xpath("//input[#class='md-input' and #type='text']")
driver.execute_script("arguments[0].scrollIntoView();", elem)
wait = WebDriverWait(driver, 10)
my_element = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[#class='md-input' and #type='text']")))
my_element.click()
I have an HTML code as follows:
<label class="top" for="id_gender2">
<div id="uniform-id_gender2" class="radio">
<span>
<input id="id_gender2" type="radio" value="2" name="id_gender">
</span>
</div>
Mrs.
</label>
The radio button is getting selected after mouse hover.
I have tried with all possible attributes for selection but I am getting element not found exception.Please let me know how to write java script in webdriver.
Try following code and let me know the result:
Actions action = new Actions(driver);
WebElement hover = driver.findElement(By.xpath("//*[#class='radio hover']"));
action.moveToElement(hover).moveToElement(driver.findElement(By.xpath("//input[#id='id_gender2']"))).click().build().perform();
UPDATE
Actually there is no need in mouse hover. Target radio seem to be initially non-clickable, so you just need extra time to wait for page complete rendering:
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#id_gender2")));
driver.findElement(By.cssSelector("input#id_gender2")).click();
Try javascript executor as follow:
WebElement element = driver.findElement(By.id("id_gender2"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
Your element is probably not loaded properly while getting error. You'd better use explicit wait in your script. Wait until your specific element loaded to be visible/clickable. I think, this may help you.
Code snippet:
By yourElementToSelect = By.id("id_gender2");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(yourElementToSelect));
driver.findElement(yourElementToSelect).click();
I am trying to automate the browser, while I try to locate the element via xpath in browser in static mode it is able to highlight the element where as when I run the script it comes back with an error that it is unable to find the element.
xpath I have written:
driver.findElement(By.xpath("//input[#value='soa_b_pbtv_l0_trnkni']/following-sibling::td[1]/child::select[#name='jobaction']")));
Here is the HTML:
<form name="f2" onsubmit="return verify();" action="/ATS/cgi-bin/barcap_jobaction.pl" method="post">
<>
<input name="jobname" type="hidden" value="soa_b_pbtv_l0_trnkni"/>
<input name="jobinstance" type="hidden" value="D03"/>
<input name="jobproceed" type="hidden" value="web"/>
<td style="background-color: #ffffff;">
<select name="jobaction">
if you're trying to select the select, jobaction then try this:
use css selector for the select select[name='jobaction']
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("form[name='f2']")));
List<WebElement> eleList = driver.findElements(By.cssSelector("form[name='f2']")));
for(WebElement element: eleList) {
if(element.findElement(By.cssSelector("input[name='jobname']")).getText().equalsIgnoringCase("expectedValue")) {
WebElement element = element.findElement(By.cssSelector("select[name='jobaction']"));
}
}
The INPUT is hidden so it won't be found using typical Selenium means. Selenium was designed to only interact with elements that a user can see and interact with. You are able to locate it in the browser because you are using JS or JQuery and they are not designed to ignore hidden elements. One way to get around this is to use JavascriptExecutor... it basically allows you to run JS in Selenium and find hidden elements. Since it sounds like you already have successful locators, I would suggest you look up some tutorials on JSE and you should be set.
If you run into a new issue while using JSE, come back and post a new question and we can try to help you.
I'm trying to find a element in selenium with this XPATH /html/body/div[3]/div/div/div[2]/div[2]/div/div/div[1]/form/div/input.
I copied it from inspect element, and copy xpath. I saw that some persons with the same problem use "*" character but I don't know where I should to use it.
this the html code
<input type="text" data-bind="value: CorpItem.Name, valueUpdate: 'afterkeydown'"
class="form-control" placeholder="Enter ..." required="required">
Here is my code on Selenium
IWebElement corpName = driver.FindElement(By.CssSelector("/html/body/div[3]/div/div/div[2]/div[2]/div/div/div[1]/form/div/input"))
Try this XPath
//input[#type='text'][#class='form-control']
In your code you used XPath and gave selector as CSS. Please verify.
Using your XPath, your code must be
IWebElement corpName = driver.FindElement(By.XPath("/html/body/div[3]/div/div/div[2]/div[2]/div/div/div[1]/form/div/input"))
If it didn't work, try
IWebElement corpName = driver.FindElement(By.XPath("//input[#type='text'][#class='form-control']"));