Milky Milky - 1 year ago 99
Java Question

How to identify and click to the button in selenium webdriver when button does not have id and title, but has hover state?

Can anyone tell me how I can identify and click to the button which does not have title?

<div class="ui-fileupload-buttonbar ui-widget-header ui-corner-top">
<span class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-fileupload-choose">
<span class="ui-button-icon-left ui-icon ui-c ui-icon-plusthick"></span>
<span class="ui-button-text ui-c">Browse</span>
<input id="j_idt126:attachments:j_idt128_input" name="j_idt126:attachments:j_idt128_input" type="file">

I have tried by below code but it is not working


How can I solve this problem in Selenium WebDriver with Java? Will be grateful for any help.

Answer Source

If you click the file upload input, you'll get a system file upload window that you cannot control.

Instead locate the element and sends the absolute path to the file you want to upload:

WebElement uploadInput = driver.findElement(By.xpath("//span[. = 'Browse']/following-sibling::input[@type='file']"));

Here we locating the input relying on the previous sibling's Browse text.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download